Exemple #1
0
 def add_handler(self, handlers, callback, method, mux):
     if self.v6:
         handlers.append(
             Handler([self.v6],
                     lambda: callback(self.v6, method, mux, handlers)))
     if self.v4:
         handlers.append(
             Handler([self.v4],
                     lambda: callback(self.v4, method, mux, handlers)))
Exemple #2
0
 def __init__(self, mux, chan, family):
     sock = socket.socket(family, socket.SOCK_DGRAM)
     Handler.__init__(self, [sock])
     self.timeout = time.time() + 30
     self.mux = mux
     self.chan = chan
     self.sock = sock
     if family == socket.AF_INET:
         self.sock.setsockopt(socket.SOL_IP, socket.IP_TTL, 42)
Exemple #3
0
 def __init__(self, mux, chan, family):
     sock = socket.socket(family, socket.SOCK_DGRAM)
     Handler.__init__(self, [sock])
     self.timeout = time.time() + 30
     self.mux = mux
     self.chan = chan
     self.sock = sock
     if family == socket.AF_INET:
         self.sock.setsockopt(socket.SOL_IP, socket.IP_TTL, 42)
Exemple #4
0
 def __init__(self, mux, chan, request):
     sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     Handler.__init__(self, [sock])
     self.sock = sock
     self.timeout = time.time()+30
     self.mux = mux
     self.chan = chan
     self.sock.setsockopt(socket.SOL_IP, socket.IP_TTL, 42)
     self.sock.connect((resolvconf_random_nameserver(), 53))
     self.sock.send(request)
Exemple #5
0
 def __init__(self, mux, chan, request):
     sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     Handler.__init__(self, [sock])
     self.sock = sock
     self.timeout = time.time() + 30
     self.mux = mux
     self.chan = chan
     self.sock.setsockopt(socket.SOL_IP, socket.IP_TTL, 42)
     self.sock.connect((resolvconf_random_nameserver(), 53))
     self.sock.send(request)
Exemple #6
0
 def __init__(self, mux, chan, request):
     sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     Handler.__init__(self, [sock])
     self.timeout = time.time() + 30
     self.mux = mux
     self.chan = chan
     self.tries = 0
     self.peer = None
     self.request = request
     self.sock = sock
     self.sock.setsockopt(socket.SOL_IP, socket.IP_TTL, 42)
     self.try_send()
Exemple #7
0
 def __init__(self, mux, chan, request):
     sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     Handler.__init__(self, [sock])
     self.timeout = time.time()+30
     self.mux = mux
     self.chan = chan
     self.tries = 0
     self.peer = None
     self.request = request
     self.sock = sock
     self.sock.setsockopt(socket.SOL_IP, socket.IP_TTL, 42)
     self.try_send()
Exemple #8
0
        # for the server to send us that message anyway.  Even if we haven't
        # set --auto-nets, we might as well wait for the message first, then
        # ignore its contents.
        mux.got_routes = None
        fw.start()
    mux.got_routes = onroutes

    def onhostlist(hostlist):
        debug2('got host list: %r\n' % hostlist)
        for line in hostlist.strip().split():
            if line:
                name,ip = line.split(',', 1)
                fw.sethostip(name, ip)
    mux.got_host_list = onhostlist

    handlers.append(Handler([listener], lambda: onaccept(listener, mux, handlers)))

    if dnslistener:
        handlers.append(Handler([dnslistener], lambda: ondns(dnslistener, mux, handlers)))

    if seed_hosts != None:
        debug1('seed_hosts: %r\n' % seed_hosts)
        mux.send(0, ssnet.CMD_HOST_REQ, '\n'.join(seed_hosts))
    
    while 1:
        rv = serverproc.poll()
        if rv:
            raise Fatal('server died with error code %d' % rv)
        
        ssnet.runonce(handlers, mux)
        if latency_control:
Exemple #9
0
 def got_host_req(data):
     if not hw.pid:
         (hw.pid, hw.sock) = start_hostwatch(data.strip().split())
         handlers.append(Handler(socks=[hw.sock], callback=hostwatch_ready))
Exemple #10
0
        debug1('Accept: %s:%r -> %s:%r.\n' %
               (srcip[0], srcip[1], dstip[0], dstip[1]))
        if dstip[1] == listener.getsockname()[1] and islocal(dstip[0]):
            debug1("-- ignored: that's my address!\n")
            sock.close()
            return
        chan = mux.next_channel()
        if not chan:
            log('warning: too many open channels.  Discarded connection.\n')
            sock.close()
            return
        mux.send(chan, ssnet.CMD_CONNECT, '%s,%s' % dstip)
        outwrap = MuxWrapper(mux, chan)
        handlers.append(Proxy(SockWrapper(sock, sock), outwrap))

    handlers.append(Handler([listener], onaccept))

    dnsreqs = {}

    def dns_done(chan, data):
        peer, timeout = dnsreqs.get(chan) or (None, None)
        debug3('dns_done: channel=%r peer=%r\n' % (chan, peer))
        if peer:
            del dnsreqs[chan]
            debug3('doing sendto %r\n' % (peer, ))
            dnslistener.sendto(data, peer)

    def ondns():
        pkt, peer = dnslistener.recvfrom(4096)
        now = time.time()
        if pkt: