<commit_before>import time
import threading

import synapse.crypto as s_crypto
import synapse.lib.threads as s_threads

from synapse.eventbus import EventBus

class NoSuchProto(Exception):pass

class TooManyTries(Exception):pass
class ImplementMe(Exception):pass

class LinkRelay:

    proto = None

    def __init__(self, link):
        self.link = link
        self._reqValidLink()

    def _reqValidLink(self):
        pass

    def _prepLinkSock(self, sock):

        sock.set('relay', self)
        sock.set('link', self.link)

        timeout = self.link[1].get('timeout')
        if timeout != None:
            sock.settimeout(timeout)

        if sock.get('listen'):
            return

        rc4key = self.link[1].get('rc4key',b'')
        zerosig = self.link[1].get('zerosig')
        if rc4key or zerosig != None:
            xform = s_crypto.Rc4Xform(rc4key)
            sock.addSockXform(xform)

    def listen(self):
        '''
        Create and return a new server Socket()
        '''
        sock = self._listen()

        sock.set('listen',True)
        self._prepLinkSock(sock)

        return sock

    def connect(self):
        '''
        Create, connect, and return a new client Socket()
        '''
        sock = self._connect()
        if sock == None:
            return None

        sock.set('connect',True)
        self._prepLinkSock(sock)

        return sock

<commit_msg>set relay and link sockinfo in LinkRelay base class<commit_after>import time
import threading

import synapse.crypto as s_crypto
import synapse.lib.threads as s_threads

from synapse.eventbus import EventBus

class NoSuchProto(Exception):pass

class TooManyTries(Exception):pass
class ImplementMe(Exception):pass

class LinkRelay:

    proto = None

    def __init__(self, link):
        self.link = link
        self._reqValidLink()

    def _reqValidLink(self):
        pass

    def _prepLinkSock(self, sock):

        sock.set('relay', self)
        sock.set('link', self.link)

        timeout = self.link[1].get('timeout')
        if timeout != None:
            sock.settimeout(timeout)

        if sock.get('listen'):
            return

        rc4key = self.link[1].get('rc4key',b'')
        zerosig = self.link[1].get('zerosig')
        if rc4key or zerosig != None:
            xform = s_crypto.Rc4Xform(rc4key)
            sock.addSockXform(xform)

    def listen(self):
        '''
        Create and return a new server Socket()
        '''
        sock = self._listen()

        sock.set('relay',self)
        sock.set('link',self.link)

        sock.set('listen',True)
        self._prepLinkSock(sock)

        return sock

    def connect(self):
        '''
        Create, connect, and return a new client Socket()
        '''
        sock = self._connect()
        if sock == None:
            return None

        sock.set('relay',self)
        sock.set('link',self.link)

        sock.set('connect',True)
        self._prepLinkSock(sock)

        return sock


{'fraction_non_alphanumeric': 0.11029411764705882, 'fraction_numerical': 0.0053475935828877, 'mean_word_length': 2.1340314136125653, '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': '6779896', 'n_tokens_mistral': 932, 'n_tokens_neox': 886, 'n_words': 210}