Fixes#118
- changed almost all "print" into logger
- threads have nicer names
- logger can have configuration in "logger.dat" in the same directory as
"keys.dat", and the logger will pick the one named "default" to replace
the "console" and "file" that are in PyBitmessage otherwise
Example file for logging to syslog:
[loggers]
keys = root,syslog
[logger_root]
level=NOTSET
handlers=syslog
[logger_syslog]
level=DEBUG
handlers=syslog
qualname=default
[handlers]
keys = syslog
[handler_syslog]
class = handlers.SysLogHandler
formatter = syslog
level = DEBUG
args=(('localhost', handlers.SYSLOG_UDP_PORT),
handlers.SysLogHandler.LOG_LOCAL7)
[formatters]
keys = syslog
[formatter_syslog]
format=%(asctime)s %(threadName)s %(filename)s@%(lineno)d %(message)s
datefmt=%b %d %H:%M:%S
print'PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download it from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\' (without quotes).'
print'Error message:',err
logger.error('PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download it from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\' (without quotes).')
print'receiveDataThread starting. ID',str(id(self))+'. The size of the shared.connectedHostsList is now',len(shared.connectedHostsList)
logger.debug('receiveDataThread starting. ID '+str(id(self))+'. The size of the shared.connectedHostsList is now '+str(len(shared.connectedHostsList)))
self.peer]# this data structure is maintained so that we can keep track of how many total objects, across all connections, are currently outstanding. If it goes too high it can indicate that we are under attack by multiple nodes working together.
@ -228,16 +218,14 @@ class receiveDataThread(threading.Thread):
self.peer]# this data structure is maintained so that we can keep track of how many total objects, across all connections, are currently outstanding. If it goes too high it can indicate that we are under attack by multiple nodes working together.
print'(concerning',str(self.peer)+')','number of objectsThatWeHaveYetToGetFromThisPeer is now',len(self.objectsThatWeHaveYetToGetFromThisPeer)
logger.debug('(concerning'+str(self.peer)+') number of objectsThatWeHaveYetToGetFromThisPeer is now '+str(len(self.objectsThatWeHaveYetToGetFromThisPeer)))
self.objectsThatWeHaveYetToGetFromThisPeer)# this data structure is maintained so that we can keep track of how many total objects, across all connections, are currently outstanding. If it goes too high it can indicate that we are under attack by multiple nodes working together.
@ -245,14 +233,12 @@ class receiveDataThread(threading.Thread):
logger.debug('number of keys(hosts) in shared.numberOfObjectsThatWeHaveYetToGetPerPeer: '+str(len(shared.numberOfObjectsThatWeHaveYetToGetPerPeer))+"\n"+ \
print'We already have',totalNumberOfobjectsThatWeHaveYetToGetFromAllPeers,'items yet to retrieve from peers and over 1000 from this node in particular. Ignoring this inv message.'
logger.debug('We already have '+str(totalNumberOfobjectsThatWeHaveYetToGetFromAllPeers)+' items yet to retrieve from peers and over 1000 from this node in particular. Ignoring this inv message.')
@ -455,8 +434,7 @@ class receiveDataThread(threading.Thread):
logger.info('inv message lists %s objects. Of those %s are new to me. It took %s seconds to figure that out.',numberOfItemsInInv,len(objectsNewToMe),time.time()-startTime)
print'We already have',totalNumberOfobjectsThatWeHaveYetToGetFromAllPeers,'items yet to retrieve from peers and over',len(self.objectsThatWeHaveYetToGetFromThisPeer),'from this node in particular. Ignoring the rest of this inv message.'
logger.debug('We already have '+str(totalNumberOfobjectsThatWeHaveYetToGetFromAllPeers)+' items yet to retrieve from peers and over '+str(len(self.objectsThatWeHaveYetToGetFromThisPeer)),' from this node in particular. Ignoring the rest of this inv message.')
break
self.someObjectsOfWhichThisRemoteNodeIsAlreadyAware[item]=0# helps us keep from sending inv messages to peers that already know about the objects listed therein
self.objectsThatWeHaveYetToGetFromThisPeer[item]=0# upon finishing dealing with an incoming message, the receiveDataThread will request a random object of from peer out of this data structure. This way if we get multiple inv messages from multiple peers which list mostly the same objects, we will make getdata requests for different random objects from the various peers.
@ -467,8 +445,7 @@ class receiveDataThread(threading.Thread):
# Send a getdata message to our peer to request the object with the given
# hash
defsendgetdata(self,hash):
withshared.printLock:
print'sending getdata to retrieve object with hash:',hash.encode('hex')
logger.debug('sending getdata to retrieve object with hash: '+hash.encode('hex'))
print'addr message does not contain the correct amount of data. Ignoring.'
logger.debug('addr message does not contain the correct amount of data. Ignoring.')
return
foriinrange(0,numberOfAddressesIncluded):
@ -590,8 +564,7 @@ class receiveDataThread(threading.Thread):
iflen(shared.knownNodes[recaddrStream])<20000andtimeSomeoneElseReceivedMessageFromThisNode>(int(time.time())-10800)andtimeSomeoneElseReceivedMessageFromThisNode<(int(time.time())+10800):# If we have more than 20000 nodes in our list already then just forget about adding more. Also, make sure that the time that someone else received a message from this node is within three hours from now.
print'Closed connection to',self.peer,'because they are interested in stream',self.streamNumber,'.'
logger.debug('Closed connection to '+str(self.peer)+' because they are interested in stream '+str(self.streamNumber)+'.')
return
shared.connectedHostsList[
self.peer.host]=1# We use this data structure to not only keep track of what hosts we are connected to so that we don't try to connect to them again, but also to list the connections count on the Network Status tab.
@ -764,8 +733,7 @@ class receiveDataThread(threading.Thread):
@ -157,35 +151,30 @@ class sendDataThread(threading.Thread):
try:
self.sendBytes(packet)
except:
withshared.printLock:
print'sendinv: self.sock.sendall failed'
logger.error('sendinv: self.sock.sendall failed')
break
elifcommand=='pong':
self.someObjectsOfWhichThisRemoteNodeIsAlreadyAware.clear()# To save memory, let us clear this data structure from time to time. As its function is to help us keep from sending inv messages to peers which sent us the same inv message mere seconds earlier, it will be fine to clear this data structure from time to time.
ifself.lastTimeISentData<(int(time.time())-298):
# Send out a pong message to keep the connection alive.