<commit_before>import errno
import threading
import time
import random
import shared
import select
import socks
import socket
import sys
import tr

from class_sendDataThread import *
from class_receiveDataThread import *
from bmconfigparser import BMConfigParser
from helper_threading import *
import knownnodes
import queues
import state

# For each stream to which we connect, several outgoingSynSender threads
# will exist and will collectively create 8 connections with peers.

class outgoingSynSender(threading.Thread, StoppableThread):

    def __init__(self):
        threading.Thread.__init__(self, name="outgoingSynSender")
        self.initStop()

    def setup(self, streamNumber, selfInitiatedConnections):
        self.streamNumber = streamNumber
        self.selfInitiatedConnections = selfInitiatedConnections

    def _getPeer(self):
        # If the user has specified a trusted peer then we'll only
        # ever connect to that. Otherwise we'll pick a random one from
        # the known nodes
        if state.trustedPeer:
            with knownnodes.knownNodesLock:
                peer = state.trustedPeer
                knownnodes.knownNodes[self.streamNumber][peer] = time.time()
        else:
            while not self._stopped:
                with knownnodes.knownNodesLock:
                    try:
                        peer, = random.sample(knownnodes.knownNodes[self.streamNumber], 1)
                    except ValueError: # no known nodes
                        self.stop.wait(1)
                        continue
                    priority = (183600 - (time.time() - knownnodes.knownNodes[self.streamNumber][peer])) / 183600 # 2 days and 3 hours
                if BMConfigParser().get('bitmessagesettings', 'socksproxytype') != 'none':
                    if peer.host.find(".onion") == -1:
                        priority /= 10 # hidden services have 10x priority over plain net
                    else:
                        # don't connect to self<commit_msg>Unnecessary locking<commit_after>import errno
import threading
import time
import random
import shared
import select
import socks
import socket
import sys
import tr

from class_sendDataThread import *
from class_receiveDataThread import *
from bmconfigparser import BMConfigParser
from helper_threading import *
import knownnodes
import queues
import state

# For each stream to which we connect, several outgoingSynSender threads
# will exist and will collectively create 8 connections with peers.

class outgoingSynSender(threading.Thread, StoppableThread):

    def __init__(self):
        threading.Thread.__init__(self, name="outgoingSynSender")
        self.initStop()

    def setup(self, streamNumber, selfInitiatedConnections):
        self.streamNumber = streamNumber
        self.selfInitiatedConnections = selfInitiatedConnections

    def _getPeer(self):
        # If the user has specified a trusted peer then we'll only
        # ever connect to that. Otherwise we'll pick a random one from
        # the known nodes
        if state.trustedPeer:
            with knownnodes.knownNodesLock:
                peer = state.trustedPeer
                knownnodes.knownNodes[self.streamNumber][peer] = time.time()
        else:
            while not self._stopped:
                try:
                    with knownnodes.knownNodesLock:
                        peer, = random.sample(knownnodes.knownNodes[self.streamNumber], 1)
                        priority = (183600 - (time.time() - knownnodes.knownNodes[self.streamNumber][peer])) / 183600 # 2 days and 3 hours
                except ValueError: # no known nodes
                    self.stop.wait(1)
                    continue
                if BMConfigParser().get('bitmessagesettings', 'socksproxytype') != 'none':
                    if peer.host.find(".onion") == -1:
                        priority /= 10 # hidden services have 10x priority over plain net
                    else:
                        # don't connect to self
{'fraction_non_alphanumeric': 0.06726457399103139, 'fraction_numerical': 0.01096163428001993, 'mean_word_length': 2.290983606557377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5977487', 'n_tokens_mistral': 1042, 'n_tokens_neox': 954, 'n_words': 318}