Changeset 628

Show
Ignore:
Timestamp:
03/10/07 21:22:04 (18 months ago)
Author:
hyriand
Message:

Commented HandshakeSocket?.cpp/h

Location:
branches/newnet/museekd/museekd
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/newnet/museekd/museekd/handshakesocket.cpp

    r613 r628  
    2727Museek::HandshakeSocket::HandshakeSocket() : NewNet::ClientSocket(), Museek::MessageProcessor(1) 
    2828{ 
     29  // Connect some signals. 
    2930  dataReceivedEvent.connect(this, &HandshakeSocket::onDataReceived); 
    3031  messageReceivedEvent.connect(this, &HandshakeSocket::onMessageReceived); 
     
    4950    case 0: 
    5051    { 
     52      // Apparently, we requested somebody to connect to us. 
    5153      NNLOG("museek.messages.handshake", "Received peer handshake message HPierceFirewall"); 
    5254      HPierceFirewall msg; 
    5355      msg.parse_network_packet(data->data, data->length); 
    5456      m_Token = msg.token; 
     57      // Tell the peer manager, it should know more. 
    5558      m_Museekd->peers()->firewallPiercedEvent(this); 
     59      // This particular socket is no longer needed. Remove it from the reactor. 
    5660      reactor()->remove(this); 
    5761      return; 
     
    5963    case 1: 
    6064    { 
     65      // Somebody wants to establish a connection. 
    6166      NNLOG("museek.messages.handshake", "Received peer handshake message HInitiate"); 
    6267      HInitiate msg; 
    6368      msg.parse_network_packet(data->data, data->length); 
    6469      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. 
    6671      m_Token = msg.token; 
    6772      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. 
    6876      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. 
    7178      receiveBuffer().clear(); 
     79      // Add the newly constructed socket to the reactor. 
    7280      reactor()->add(that); 
     81      // Remove this socket from the reactor as it's no longer needed. 
    7382      reactor()->remove(this); 
    7483      return; 
  • branches/newnet/museekd/museekd/handshakesocket.h

    r613 r628  
    2929  class Museekd; 
    3030 
     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. */ 
    3134  class HandshakeSocket : public NewNet::ClientSocket, public MessageProcessor 
    3235  { 
     
    4144    } 
    4245 
     46    /* Return the token the remote peer sent. */ 
    4347    uint token() const 
    4448    { 
     
    4650    } 
    4751 
     52    /* Return the username the remote peer claims it is. */ 
    4853    const std::string & user() const 
    4954    { 
     
    5257 
    5358  private: 
     59    /* Handler for messageReceivedEvent. */ 
    5460    void onMessageReceived(const MessageData * data); 
    5561