Beispiel #1
0
 def client_threads_factory(self, service, server_ip):
     return {
         "SIGN_UP": P2P(conf["SIGN_UP"], server_ip, True),
         "HEARTBEAT": P2P(conf["HEARTBEAT"], server_ip, True),
         "QUERY": P2P(conf["QUERY"], server_ip, True),
         "RETRIEVE": P2P(conf["RETRIEVE"], server_ip, True)
     }.get(service.upper())
Beispiel #2
0
 def start_server(self):
     threads = [
         P2P(conf["SIGN_UP"]),
         P2P(conf["QUERY"]),
         P2P(conf["HEARTBEAT"]),
         P2P(conf["RETRIEVE"])
     ]
     print("[-] Running server...")
     self.run_threads(threads)
Beispiel #3
0
    def test_preserve_embedded_tags(self):
        data = {
            'slug': 'la_na_test_create_update_delete-htmlstory',
            'title': 'Testing creating, updating and deletion',
            'body': 'lorem ipsum 3',
            'content_item_type_code': 'htmlstory',
        }

        conn = P2P(auth_token=os.environ['P2P_API_KEY'],
                   preserve_embedded_tags=False)

        try:
            result = conn.create_content_item(data)
        except P2PSlugTaken:
            conn.delete_content_item(data['slug'])
            result = conn.create_content_item(data)

        data2 = data.copy()
        data2['body'] = 'Lorem ipsum foo bar'
        result2 = conn.update_content_item(data2)
        self.assertTrue(conn.delete_content_item(data['slug']))

        self.assertIn('html_story', result.keys())
        res = result['html_story']
        self.assertEqual(res['slug'], data['slug'])
        self.assertEqual(res['title'], data['title'])
        self.assertEqual(res['body'].strip(), data['body'])

        res = result2
        self.assertEqual(res, {})
Beispiel #4
0
def init_p2p(last_block_num):
    # P2P initialization
    p2p = P2P(last_block_num)
    while (p2p.bootstrap()):
        time.sleep(1)
    mainLog.info(
        "P2P Bootstrap finished. Wait 10 sec. for inter-process communication")
    time.sleep(10)
    return p2p
Beispiel #5
0
                        number=blocks[i].header.number + 1))
        blocks[i + 1] = b
        num_blocks += 1


def gen_tx_pool():
    global tx_pool
    tx = Transaction(5, 3, '54450450e24286143a35686ad77a7c851ada01a0', 2,
                     '2001:db8::1/16', [2, '2001:cdba:9abc:5678::', 20, 230])
    tx_pool.append(tx)


if __name__ == '__main__':
    gen_blocks(100)
    gen_tx_pool()
    p2p = P2P(num_blocks)
    while (p2p.bootstrap()):
        pass
    p2p.start_notifications()
    #start = time.time()
    end = False
    while not end:
        # Process Block
        #print "Process Block"
        try:
            block = p2p.get_block()
            while block is not None:
                blocks[block.header.number] = block
                print block.header.number
                block = p2p.get_block()
        except Exception as e:
Beispiel #6
0
from p2p import P2P
import threading
import time

# create_session()
# close_connection()
# kill_server
# send
# raw_send
# get_request
# check_request
# check_address

PORT = 11337
MAX_CLIENTS = 2
p2p = P2P(PORT, MAX_CLIENTS)


def connect():
    ADDRESS = input('IP: ')
    if not p2p.check_address(ADDRESS):
        thread = threading.Thread(target=p2p.create_session,
                                  name=ADDRESS,
                                  args=(ADDRESS, ))
        thread.start()
        time.sleep(1)
        if p2p.check_address(ADDRESS):
            print(f'Connection to {ADDRESS} succeed')
        else:
            print(f'Connection to {ADDRESS} failed')
            thread.join()
Beispiel #7
0
 def __init__(self, socket):
     self.socket = socket
     self.blockchain = [ block.genesis_block ]
     self.p2p = P2P(self, socket)