Beispiel #1
0
 def _tcp_sock_from_meta(self, meta):
     assert meta.host
     if meta.ia is None:
         meta.ia = self.addr.isd_as
     if meta.path is None:
         meta.path = SCIONPath()
     dst = meta.get_addr()
     first_ip, first_port = self._get_first_hop(meta.path, dst)
     active = True
     try:
         # Create low-level TCP socket and connect
         sock = SCIONTCPSocket()
         sock.bind((self.addr, 0))
         sock.connect(dst,
                      meta.port,
                      meta.path,
                      first_ip,
                      first_port,
                      flags=meta.flags)
     except SCIONTCPError:
         log_exception(
             "TCP: connection init error, marking socket inactive")
         sock = None
         active = False
     # Create and return TCPSocketWrapper
     return TCPSocketWrapper(sock, dst, meta.path, active)
Beispiel #2
0
 def _tcp_accept_loop(self):
     while self.run_flag.is_set():
         try:
             logging.debug("TCP: waiting for connections")
             self._tcp_conns_put(TCPSocketWrapper(*self._tcp_sock.accept()))
             logging.debug("TCP: accepted connection")
         except SCIONTCPTimeout:
             pass
         except SCIONTCPError:
             log_exception("TCP: error on accept()")
             logging.error("TCP: leaving the accept loop")
             break
     try:
         self._tcp_sock.close()
     except SCIONTCPError:
         log_exception("TCP: error on closing _tcp_sock")