Example #1
0
    def handshake(self):
        """
    Confirm that we are talking to a Switzerland client, with the appropriate
    protocol version.  If we return false the Protocl should clean up for us.
    """

        self.debug_note("attempting handshake with %s" % repr(self.peer))
        self.socket.settimeout(30)
        try:
            msg = self.socket.recv(len(Protocol.handshake1))
        except s.timeout:
            self.protocol_error("Timeout before handshake")

        if msg[:len(Protocol.handshake1) - 2] != Protocol.handshake1[:-2]:
            self.debug_note("Not the start of a Switzerland session:\n" +
                            Protocol.handshake1[:-2],
                            seriousness=11)
            return False

        incoming_prot_ver = Protocol.parse_version(msg[-2:])

        if incoming_prot_ver not in Protocol.supported_protocol_versions:
            self.socket.send(Protocol.no_common_version)
            self.debug_note("Alice is using unsupported protocol version %d" %
                            incoming_prot_ver,
                            seriousness=11)
            return False
        self.socket.setblocking(1)
        self.socket.send(Protocol.handshake2)
        self.debug_note("completed handshake with %s" % repr(self.peer))
        return True
  def handshake(self):
    """
    Confirm that we are talking to a Switzerland client, with the appropriate
    protocol version.  If we return false the Protocl should clean up for us.
    """
    
    self.debug_note("attempting handshake with %s" % repr(self.peer))
    self.socket.settimeout(30)
    try:
      msg = self.socket.recv(len(Protocol.handshake1))
    except s.timeout:
      self.protocol_error("Timeout before handshake")
      
    if msg[:len(Protocol.handshake1) - 2] != Protocol.handshake1[:-2]:
      self.debug_note("Not the start of a Switzerland session:\n"+Protocol.handshake1[:-2], seriousness=11)
      return False

    incoming_prot_ver = Protocol.parse_version(msg[-2:])

    if incoming_prot_ver not in Protocol.supported_protocol_versions:
      self.socket.send(Protocol.no_common_version)
      self.debug_note("Alice is using unsupported protocol version %d" 
                   % incoming_prot_ver, seriousness=11)
      return False
    self.socket.setblocking(1)
    self.socket.send(Protocol.handshake2)
    self.debug_note("completed handshake with %s" % repr(self.peer))
    return True
Example #3
0
    self.socket.settimeout(30)
    try:
      msg = self.socket.recv(len(Protocol.handshake2))
    except s.timeout:
      self.debug_note("Timeout during handshake", seriousness=11)
      return False
    except s.error, e:
      log.error("error during handshake: %s" % e)
      return False
    except:
      log.error("error during handshake")
      return False

    if msg[:-2] == Protocol.no_common_version[:-2]:
      log.error("Server refuses to speak protocols before version %d; we need version %d" % (Protocol.parse_version(msg[-2:]), Protocol.protocol_version))
      return False
    
    elif msg[:-2] != Protocol.handshake2[:-2]:
      log.error("Handshake failed, wasn't expecting:\n" + msg)
      return False

    log.debug("Started session with version %d" % Protocol.parse_version(msg[-2:]))
    self.socket.setblocking(1)
    return True

  def setup(self):
    "Handshake successful; now do initial housekeeping"
    self.send_myip()

  def lookup_flow_by_id(self, flow_id, caller):
Example #4
0
            msg = self.socket.recv(len(Protocol.handshake2))
        except s.timeout:
            self.debug_note("Timeout during handshake", seriousness=11)
            return False
        except s.error, e:
            log.error("error during handshake: %s" % e)
            return False
        except:
            log.error("error during handshake")
            return False

        if msg[:-2] == Protocol.no_common_version[:-2]:
            log.error(
                "Server refuses to speak protocols before version %d; we need version %d"
                %
                (Protocol.parse_version(msg[-2:]), Protocol.protocol_version))
            return False

        elif msg[:-2] != Protocol.handshake2[:-2]:
            log.error("Handshake failed, wasn't expecting:\n" + msg)
            return False

        log.debug("Started session with version %d" %
                  Protocol.parse_version(msg[-2:]))
        self.socket.setblocking(1)
        return True

    def setup(self):
        "Handshake successful; now do initial housekeeping"
        self.send_myip()