Пример #1
0
    def start_dispersy(self):

        class DispersySocket(object):

            def __init__(self, rawserver, dispersy, port, ip = '0.0.0.0'):
                while True:
                    try:
                        self.socket = rawserver.create_udpsocket(port, ip)
                    except socket.error as error:
                        port += 1
                        continue

                    break

                self.rawserver = rawserver
                self.rawserver.start_listening_udp(self.socket, self)
                self.dispersy = dispersy

            def get_address(self):
                return self.socket.getsockname()

            def data_came_in(self, packets):
                if packets:
                    try:
                        self.dispersy.data_came_in(packets)
                    except:
                        log_exc()
                        raise

            def send(self, address, data):
                try:
                    self.socket.sendto(data, address)
                except socket.error as error:
                    if error[0] == SOCKET_BLOCK_ERRORCODE:
                        self.sendqueue.append((data, address))
                        self.rawserver.add_task(self.process_sendqueue, 0.1)

        config = self.session.sessconfig
        sqlite_db_path = os.path.join(config['state_dir'], u'sqlite')
        if not os.path.isdir(sqlite_db_path):
            os.makedirs(sqlite_db_path)
        self.dispersy = Dispersy.get_instance(self.dispersy_rawserver, sqlite_db_path)
        self.dispersy.socket = DispersySocket(self.rawserver, self.dispersy, config['dispersy_port'])
        from freestream.Core.Overlay.permid import read_keypair
        keypair = read_keypair(self.session.get_permid_keypair_filename())
        from freestream.Core.dispersy.crypto import ec_to_public_bin, ec_to_private_bin
        from freestream.Core.dispersy.member import MyMember
        self.session.dispersy_member = MyMember(ec_to_public_bin(keypair), ec_to_private_bin(keypair))
        AllChannelCommunity.load_communities(self.session.dispersy_member)
        communities = ChannelCommunity.load_communities()
        self.session.uch.notify(NTFY_DISPERSY, NTFY_STARTED, None)
Пример #2
0
 def load(filename):
     keypair = permidmod.read_keypair(filename)
     return ECDSALiveSourceAuthConfig(keypair)
Пример #3
0
def read_cs_keypair(keypair_filename):
    return permid.read_keypair(keypair_filename)
Пример #4
0
def read_cs_keypair(keypair_filename):
    return permid.read_keypair(keypair_filename)