This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Merged
Networking fixes #480
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,13 +175,25 @@ impl Connection { | |
self.socket.peer_addr() | ||
} | ||
|
||
pub fn try_clone(&self) -> io::Result<Self> { | ||
Ok(Connection { | ||
token: self.token, | ||
socket: try!(self.socket.try_clone()), | ||
rec_buf: Vec::new(), | ||
rec_size: 0, | ||
send_queue: self.send_queue.clone(), | ||
interest: EventSet::hup() | EventSet::readable(), | ||
stats: self.stats.clone(), | ||
}) | ||
} | ||
|
||
/// Register this connection with the IO event loop. | ||
pub fn register_socket<Host: Handler>(&self, reg: Token, event_loop: &mut EventLoop<Host>) -> io::Result<()> { | ||
trace!(target: "net", "connection register; token={:?}", reg); | ||
event_loop.register(&self.socket, reg, self.interest, PollOpt::edge() | PollOpt::oneshot()).or_else(|e| { | ||
if let Err(e) = event_loop.register(&self.socket, reg, self.interest, PollOpt::edge() | PollOpt::oneshot()) { | ||
debug!("Failed to register {:?}, {:?}", reg, e); | ||
Ok(()) | ||
}) | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Update connection registration. Should be called at the end of the IO handler. | ||
|
@@ -265,7 +277,7 @@ impl EncryptedConnection { | |
} | ||
|
||
/// Create an encrypted connection out of the handshake. Consumes a handshake object. | ||
pub fn new(mut handshake: Handshake) -> Result<EncryptedConnection, UtilError> { | ||
pub fn new(handshake: &mut Handshake) -> Result<EncryptedConnection, UtilError> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if it consumes the object, why not pass it by move rather than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not anymore, I'll update the comment |
||
let shared = try!(crypto::ecdh::agree(handshake.ecdhe.secret(), &handshake.remote_public)); | ||
let mut nonce_material = H512::new(); | ||
if handshake.originated { | ||
|
@@ -300,9 +312,8 @@ impl EncryptedConnection { | |
ingress_mac.update(&mac_material); | ||
ingress_mac.update(if handshake.originated { &handshake.ack_cipher } else { &handshake.auth_cipher }); | ||
|
||
handshake.connection.expect(ENCRYPTED_HEADER_LEN); | ||
Ok(EncryptedConnection { | ||
connection: handshake.connection, | ||
let mut enc = EncryptedConnection { | ||
connection: try!(handshake.connection.try_clone()), | ||
encoder: encoder, | ||
decoder: decoder, | ||
mac_encoder: mac_encoder, | ||
|
@@ -311,7 +322,9 @@ impl EncryptedConnection { | |
read_state: EncryptedConnectionState::Header, | ||
protocol_id: 0, | ||
payload_len: 0 | ||
}) | ||
}; | ||
enc.connection.expect(ENCRYPTED_HEADER_LEN); | ||
Ok(enc) | ||
} | ||
|
||
/// Send a packet | ||
|
@@ -440,6 +453,12 @@ impl EncryptedConnection { | |
Ok(()) | ||
} | ||
|
||
/// Register socket with the event lpop. This should be called at the end of the event loop. | ||
pub fn register_socket<Host:Handler>(&self, reg: Token, event_loop: &mut EventLoop<Host>) -> Result<(), UtilError> { | ||
try!(self.connection.register_socket(reg, event_loop)); | ||
Ok(()) | ||
} | ||
|
||
/// Update connection registration. This should be called at the end of the event loop. | ||
pub fn update_socket<Host:Handler>(&self, reg: Token, event_loop: &mut EventLoop<Host>) -> Result<(), UtilError> { | ||
try!(self.connection.update_socket(reg, event_loop)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing docs?