(self)
| 114 | return True |
| 115 | |
| 116 | def run(self): |
| 117 | logger.debug('sendDataThread starting. ID: ' + str(id(self)) + '. Number of queues in sendDataQueues: ' + str(len(state.sendDataQueues))) |
| 118 | while self.sendBytes(): |
| 119 | deststream, command, data = self.sendDataThreadQueue.get() |
| 120 | |
| 121 | if deststream == 0 or deststream in self.streamNumber: |
| 122 | if command == 'shutdown': |
| 123 | logger.debug('sendDataThread (associated with ' + str(self.peer) + ') ID: ' + str(id(self)) + ' shutting down now.') |
| 124 | break |
| 125 | # When you receive an incoming connection, a sendDataThread is |
| 126 | # created even though you don't yet know what stream number the |
| 127 | # remote peer is interested in. They will tell you in a version |
| 128 | # message and if you too are interested in that stream then you |
| 129 | # will continue on with the connection and will set the |
| 130 | # streamNumber of this send data thread here: |
| 131 | elif command == 'setStreamNumber': |
| 132 | self.streamNumber = data |
| 133 | logger.debug('setting the stream number to %s', ', '.join(str(x) for x in self.streamNumber)) |
| 134 | elif command == 'setRemoteProtocolVersion': |
| 135 | specifiedRemoteProtocolVersion = data |
| 136 | logger.debug('setting the remote node\'s protocol version in the sendDataThread (ID: ' + str(id(self)) + ') to ' + str(specifiedRemoteProtocolVersion)) |
| 137 | self.remoteProtocolVersion = specifiedRemoteProtocolVersion |
| 138 | elif command == 'advertisepeer': |
| 139 | self.objectHashHolderInstance.holdPeer(data) |
| 140 | elif command == 'sendaddr': |
| 141 | if self.connectionIsOrWasFullyEstablished: # only send addr messages if we have sent and heard a verack from the remote node |
| 142 | numberOfAddressesInAddrMessage = len(data) |
| 143 | payload = '' |
| 144 | for hostDetails in data: |
| 145 | timeLastReceivedMessageFromThisNode, streamNumber, services, host, port = hostDetails |
| 146 | payload += pack( |
| 147 | '>Q', timeLastReceivedMessageFromThisNode) # now uses 64-bit time |
| 148 | payload += pack('>I', streamNumber) |
| 149 | payload += pack( |
| 150 | '>q', services) # service bit flags offered by this node |
| 151 | payload += protocol.encodeHost(host) |
| 152 | payload += pack('>H', port) |
| 153 | |
| 154 | payload = encodeVarint(numberOfAddressesInAddrMessage) + payload |
| 155 | packet = protocol.CreatePacket('addr', payload) |
| 156 | try: |
| 157 | self.sendBytes(packet) |
| 158 | except: |
| 159 | logger.error('sendaddr: self.sock.sendall failed') |
| 160 | break |
| 161 | elif command == 'advertiseobject': |
| 162 | self.objectHashHolderInstance.holdHash(data) |
| 163 | elif command == 'sendinv': |
| 164 | if self.connectionIsOrWasFullyEstablished: # only send inv messages if we have send and heard a verack from the remote node |
| 165 | payload = '' |
| 166 | for hash in data: |
| 167 | payload += hash |
| 168 | if payload != '': |
| 169 | payload = encodeVarint(len(payload)/32) + payload |
| 170 | packet = protocol.CreatePacket('inv', payload) |
| 171 | try: |
| 172 | self.sendBytes(packet) |
| 173 | except: |
nothing calls this directly
no test coverage detected