def send(self): payload = Network.sendData(self.addrRecv, self.serialize()) message = MessageFactory.getInstance(MessageType.INV) message.addrRecv = self.addrRecv if message.deserialize(payload): message.onSuccess() else: message.onFailure(self.sendFailure)
def discoverInternetGatewayDevices(): payload, addr = Network.sendDataByUDP(M_SEARCH_HOST, M_SEARCH_PORT, M_SEARCH_QUERY) payload = DataType.asString(payload) for data in payload.split(M_SEARCH_ESCAPE): if data.startswith('LOCATION'): location = data.split(" ") INTERNET_GATEWAY_DEVICE_LOCATIONS[addr] = location[1]
def send(self): payload = Network.sendData(self.addrRecv, self.serialize()) message = MessageFactory.getInstance(MessageType.ADDR) if message.deserialize(payload): message.onSuccess() else: peer = Peer() peer.host = self.addrRecv Peers.removePeer(peer) message.onFailure(self.sendFailure)
class Peers: db = Config.getValue("PEERS_DB") subDb = Config.getValue("PEERS_SUB_DB") peers = Storage(db, subDb) hostname = Network.getHostname() ipAddress = Network.getIpAddress() if Config.getBoolValue('PEERS_ENABLE_SEEDS'): with open(Config.getValue('SEEDS_DIR')) as seeds: hosts = json.load(seeds) for host in hosts: if host != hostname and host != ipAddress: hostBytes = DataType.serialize(host) if peers.get(hostBytes) == None: peer = Peer() peer.host = host peer.lastUpdate = DataType.asTime() peers.set(hostBytes, peer.serialize())
def send(self): peer = Peers.getPeerByHost(self.addrRecv) self.blockHashes.append(peer.chainHeadBlockHash) payload = Network.sendData(self.addrRecv, self.serialize()) message = MessageFactory.getInstance(MessageType.INV) message.addrFrom = self.addrRecv if message.deserialize(payload): message.onSuccess() else: message.onFailure(self.sendFailure)
def handleArguments(arguments): httpPort = Http.getHttpPort() socketPort = Network.getSocketPort() if arguments.service_port: httpPort = arguments.service_port Http.setHttpPort(httpPort) if arguments.node_port: socketPort = arguments.node_port Network.setSocketPort(socketPort) if Config.getBoolValue("ENABLE_HTTP_SERVICE"): httpNode = HttpNode(httpPort) httpNode.start() UPnP.addPortMapping(socketPort) socketNode = SocketNode(socketPort) socketNode.sync() socketNode.start()
def addPortMapping(port): with open("recip/network/messages/upnp/AddPortMapping.xml", "r") as upnp: payload = upnp.read() payload = payload % (port, port, Network.getIpAddress(False), Config.getValue('NODE_VERSION')) headers = { 'SOAPAction': '"urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"', 'Content-Type': 'text/xml' } for igd in INTERNET_GATEWAY_DEVICES: xml = Http.send(igd, payload, False, headers) return xmlFindText(xml, 'AddPortMappingResponse')
def send(self): payload = Network.sendData(self.addrRecv, self.serialize()) isValid = True message = MessageFactory.getInstance(MessageType.PONG) if message.deserialize(payload): if message.nonce == self.nonce: message.onSuccess() else: isValid = False else: isValid = False if isValid == False: peer = Peer() peer.host = self.addrRecv Peers.removePeer(peer) message.onFailure(self.sendFailure)
def send(self): peer = Peers.getPeerByHost(self.addrRecv) if peer.lastVersionNonce == None: peer.lastVersionNonce = self.nonce Peers.addPeer(peer) else: self.nonce = peer.lastVersionNonce chainHeadBlock = Chain.getChain().getChainHeadBlock() self.chainHeadBlockHash = chainHeadBlock.hash() payload = Network.sendData(self.addrRecv, self.serialize()) message = MessageFactory.getInstance(MessageType.VERACK) message.addrFrom = self.addrRecv if message.deserialize(payload): message.onSuccess() else: peer = Peer() peer.host = self.addrRecv Peers.removePeer(peer) message.onFailure(self.sendFailure)
def __init__(self): self.addrRecv = None self.addrFrom = Network.getHostname()
def send(self): Network.sendData(self.addrRecv, self.serialize(), False)
def sendFailure(self, message): Network.sendData(self.addrRecv, message, False)
def send(self): self.addrList.append(self.addrFrom) Network.sendData(self.addrRecv, self.serialize(), False)
def handle(self): payload = Network.getSocketPayload(self.request) payload = RLP.decode(payload) self.handlePayload(payload)
def getAddrFrom(self): addrFrom = self.request.getpeername() return "{0}{1}{2}".format(addrFrom[0], ':', Network.getSocketPort())
def getAddrRecv(self): addrRecv = self.request.getsockname() return "{0}{1}{2}".format(addrRecv[0], ':', Network.getSocketPort())