def try_add_known_node(stream, addr, port, method=''): try: socket.inet_aton(addr) except (TypeError, socket.error): return logger.info('Adding %s to knownNodes based on %s DNS bootstrap method', addr, method) knownnodes.addKnownNode(stream, state.Peer(addr, port))
def handle_close(self): """Callback for connection being closed.""" host_is_global = self.isOutbound or not self.local and not state.socksIP if self.fullyEstablished: UISignalQueue.put(( 'updateNetworkStatusTab', (self.isOutbound, False, self.destination) )) if host_is_global: knownnodes.addKnownNode( self.streams, self.destination, time.time()) Dandelion().maybeRemoveStem(self) elif host_is_global: knownnodes.decreaseRating(self.destination) BMProto.handle_close(self)
def set_connection_fully_established(self): """Initiate inventory synchronisation.""" if not self.isOutbound and not self.local: state.clientHasReceivedIncomingConnections = True UISignalQueue.put(('setStatusIcon', 'green')) UISignalQueue.put(( 'updateNetworkStatusTab', (self.isOutbound, True, self.destination) )) self.antiIntersectionDelay(True) self.fullyEstablished = True # The connection having host suitable for knownnodes if self.isOutbound or not self.local and not state.socksIP: knownnodes.increaseRating(self.destination) knownnodes.addKnownNode( self.streams, self.destination, time.time()) Dandelion().maybeAddStem(self) self.sendAddr() self.sendBigInv()
def processonion(data): """Process onionpeer object""" readPosition = 20 # bypass the nonce, time, and object type length = decodeVarint(data[readPosition:readPosition + 10])[1] readPosition += length stream, length = decodeVarint(data[readPosition:readPosition + 10]) readPosition += length # it seems that stream is checked in network.bmproto port, length = decodeVarint(data[readPosition:readPosition + 10]) host = protocol.checkIPAddress(data[readPosition + length:]) if not host: return peer = state.Peer(host, port) with knownnodes.knownNodesLock: knownnodes.addKnownNode(stream, peer, is_self=state.ownAddresses.get(peer))
def bm_command_addr(self): """Incoming addresses, process them""" # pylint: disable=redefined-outer-name addresses = self._decode_addr() for seenTime, stream, _, ip, port in addresses: decodedIP = protocol.checkIPAddress(str(ip)) if stream not in state.streamsInWhichIAmParticipating: continue if (decodedIP and time.time() - seenTime > 0 and seenTime > time.time() - ADDRESS_ALIVE and port > 0): peer = Peer(decodedIP, port) with knownnodes.knownNodesLock: # isnew = knownnodes.addKnownNode(stream, peer, seenTime) # since we don't track peers outside of knownnodes, # only spread if in knownnodes to prevent flood # DISABLED TO WORKAROUND FLOOD/LEAK # if isnew: # addrQueue.put(( # stream, peer, seenTime, self.destination)) return True
def dns(): """ DNS bootstrap. This could be programmed to use the SOCKS proxy to do the DNS lookup some day but for now we will just rely on the entries in defaultKnownNodes.py. Hopefully either they are up to date or the user has run Bitmessage recently without SOCKS turned on and received good bootstrap nodes using that method. """ def try_add_known_node(stream, addr, port, method=''): try: socket.inet_aton(addr) except (TypeError, socket.error): return logger.info('Adding %s to knownNodes based on %s DNS bootstrap method', addr, method) knownnodes.addKnownNode(stream, state.Peer(addr, port)) proxy_type = BMConfigParser().get('bitmessagesettings', 'socksproxytype') if proxy_type == 'none': for port in [8080, 8444]: try: for item in socket.getaddrinfo( 'bootstrap%s.bitmessage.org' % port, 80): try_add_known_node(1, item[4][0], port) except: logger.error( 'bootstrap%s.bitmessage.org DNS bootstrapping failed.', port, exc_info=True) elif proxy_type == 'SOCKS5': knownnodes.addKnownNode(1, state.Peer('quzwelsuziwqgpt2.onion', 8444)) logger.debug("Adding quzwelsuziwqgpt2.onion:8444 to knownNodes.") for port in [8080, 8444]: logger.debug("Resolving %i through SOCKS...", port) address_family = socket.AF_INET sock = socks.socksocket(address_family, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.settimeout(20) proxytype = socks.PROXY_TYPE_SOCKS5 sockshostname = BMConfigParser().get('bitmessagesettings', 'sockshostname') socksport = BMConfigParser().getint('bitmessagesettings', 'socksport') # Do domain name lookups through the proxy; # though this setting doesn't really matter since we won't # be doing any domain name lookups anyway. rdns = True if BMConfigParser().getboolean('bitmessagesettings', 'socksauthentication'): socksusername = BMConfigParser().get('bitmessagesettings', 'socksusername') sockspassword = BMConfigParser().get('bitmessagesettings', 'sockspassword') sock.setproxy(proxytype, sockshostname, socksport, rdns, socksusername, sockspassword) else: sock.setproxy(proxytype, sockshostname, socksport, rdns) try: ip = sock.resolve("bootstrap" + str(port) + ".bitmessage.org") sock.shutdown(socket.SHUT_RDWR) sock.close() except: logger.error("SOCKS DNS resolving failed", exc_info=True) else: try_add_known_node(1, ip, port, 'SOCKS') else: logger.info( 'DNS bootstrap skipped because the proxy type does not support' ' DNS resolution.')