@ -4,6 +4,7 @@ import socket
from class_sendDataThread import *
from class_receiveDataThread import *
import helper_bootstrap
from helper_threading import *
import errno
import re
@ -15,10 +16,11 @@ import re
# (within the recversion function of the recieveData thread)
class singleListener ( threading . Thread ):
class singleListener ( threading . Thread , StoppableThread ):
def __init__ ( self ) :
threading . Thread . __init__ ( self , name = " singleListener " )
self . initStop ( )
def setup ( self , selfInitiatedConnections ) :
self . selfInitiatedConnections = selfInitiatedConnections
@ -37,6 +39,16 @@ class singleListener(threading.Thread):
sock . bind ( ( HOST , PORT ) )
sock . listen ( 2 )
return sock
def stopThread ( self ) :
super ( singleListener , self ) . stopThread ( )
s = socket . socket ( socket . AF_INET , socket . SOCK_STREAM )
try :
s . connect ( ( ' 127.0.0.1 ' , shared . config . getint ( ' bitmessagesettings ' , ' port ' ) ) )
s . shutdown ( socket . SHUT_RDWR )
s . close ( )
except :
pass
def run ( self ) :
# If there is a trusted peer then we don't want to accept
@ -44,15 +56,15 @@ class singleListener(threading.Thread):
if shared . trustedPeer :
return
while shared . safeConfigGetBoolean ( ' bitmessagesettings ' , ' dontconnect ' ) :
time . sleep ( 1 )
while shared . safeConfigGetBoolean ( ' bitmessagesettings ' , ' dontconnect ' ) and shared . shutdown == 0 :
self . stop . wait ( 1 )
helper_bootstrap . dns ( )
# We typically don't want to accept incoming connections if the user is using a
# SOCKS proxy, unless they have configured otherwise. If they eventually select
# proxy 'none' or configure SOCKS listening then this will start listening for
# connections.
while shared . config . get ( ' bitmessagesettings ' , ' socksproxytype ' ) [ 0 : 5 ] == ' SOCKS ' and not shared . config . getboolean ( ' bitmessagesettings ' , ' sockslisten ' ) :
time . sleep ( 5 )
while shared . config . get ( ' bitmessagesettings ' , ' socksproxytype ' ) [ 0 : 5 ] == ' SOCKS ' and not shared . config . getboolean ( ' bitmessagesettings ' , ' sockslisten ' ) and shared . shutdown == 0 :
self . stop . wait ( 5 )
logger . info ( ' Listening for incoming connections. ' )
@ -73,19 +85,19 @@ class singleListener(threading.Thread):
# regexp to match an IPv4-mapped IPv6 address
mappedAddressRegexp = re . compile ( r ' ^::ffff:([0-9]+ \ .[0-9]+ \ .[0-9]+ \ .[0-9]+)$ ' )
while True :
while shared . shutdown == 0 :
# We typically don't want to accept incoming connections if the user is using a
# SOCKS proxy, unless they have configured otherwise. If they eventually select
# proxy 'none' or configure SOCKS listening then this will start listening for
# connections.
while shared . config . get ( ' bitmessagesettings ' , ' socksproxytype ' ) [ 0 : 5 ] == ' SOCKS ' and not shared . config . getboolean ( ' bitmessagesettings ' , ' sockslisten ' ) :
time . sleep ( 10 )
while len ( shared . connectedHostsList ) > 220 :
while shared . config . get ( ' bitmessagesettings ' , ' socksproxytype ' ) [ 0 : 5 ] == ' SOCKS ' and not shared . config . getboolean ( ' bitmessagesettings ' , ' sockslisten ' ) and shared . shutdown == 0 :
self . stop . wait ( 10 )
while len ( shared . connectedHostsList ) > 220 and shared . shutdown == 0 :
logger . info ( ' We are connected to too many people. Not accepting further incoming connections for ten seconds. ' )
time . sleep ( 10 )
self . stop . wait ( 10 )
while True :
while shared . shutdown == 0 :
socketObject , sockaddr = sock . accept ( )
( HOST , PORT ) = sockaddr [ 0 : 2 ]