Changeset 628
- Timestamp:
- 03/10/07 21:22:04 (18 months ago)
- Location:
- branches/newnet/museekd/museekd
- Files:
-
- 2 modified
-
handshakesocket.cpp (modified) (3 diffs)
-
handshakesocket.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/newnet/museekd/museekd/handshakesocket.cpp
r613 r628 27 27 Museek::HandshakeSocket::HandshakeSocket() : NewNet::ClientSocket(), Museek::MessageProcessor(1) 28 28 { 29 // Connect some signals. 29 30 dataReceivedEvent.connect(this, &HandshakeSocket::onDataReceived); 30 31 messageReceivedEvent.connect(this, &HandshakeSocket::onMessageReceived); … … 49 50 case 0: 50 51 { 52 // Apparently, we requested somebody to connect to us. 51 53 NNLOG("museek.messages.handshake", "Received peer handshake message HPierceFirewall"); 52 54 HPierceFirewall msg; 53 55 msg.parse_network_packet(data->data, data->length); 54 56 m_Token = msg.token; 57 // Tell the peer manager, it should know more. 55 58 m_Museekd->peers()->firewallPiercedEvent(this); 59 // This particular socket is no longer needed. Remove it from the reactor. 56 60 reactor()->remove(this); 57 61 return; … … 59 63 case 1: 60 64 { 65 // Somebody wants to establish a connection. 61 66 NNLOG("museek.messages.handshake", "Received peer handshake message HInitiate"); 62 67 HInitiate msg; 63 68 msg.parse_network_packet(data->data, data->length); 64 69 NNLOG("museek.debug", "HInitiate payload: %s %s %u", msg.user.c_str(), msg.type.c_str(), msg.token); 65 receiveBuffer().seek(data->length + 5);70 // Set some variables. 66 71 m_Token = msg.token; 67 72 m_User = msg.user; 73 // Seek past the message. 74 receiveBuffer().seek(data->length + 5); 75 // Create a new PeerSocket which will copy our descriptor and state. 68 76 Museek::PeerSocket * that = new Museek::PeerSocket(this); 69 that->setToken(msg.token); 70 that->setUser(msg.user); 77 // Clear our receive buffer so we stop processing data. 71 78 receiveBuffer().clear(); 79 // Add the newly constructed socket to the reactor. 72 80 reactor()->add(that); 81 // Remove this socket from the reactor as it's no longer needed. 73 82 reactor()->remove(this); 74 83 return; -
branches/newnet/museekd/museekd/handshakesocket.h
r613 r628 29 29 class Museekd; 30 30 31 /* HandshakeSocket is used when a new incoming connection has been 32 established. HandshakeSocket reads one message then creates the 33 appropriate socket type re-using the same descriptor. */ 31 34 class HandshakeSocket : public NewNet::ClientSocket, public MessageProcessor 32 35 { … … 41 44 } 42 45 46 /* Return the token the remote peer sent. */ 43 47 uint token() const 44 48 { … … 46 50 } 47 51 52 /* Return the username the remote peer claims it is. */ 48 53 const std::string & user() const 49 54 { … … 52 57 53 58 private: 59 /* Handler for messageReceivedEvent. */ 54 60 void onMessageReceived(const MessageData * data); 55 61
