forked from Tribler/py-ipv8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
133 lines (115 loc) · 3.38 KB
/
Copy pathmain.py
File metadata and controls
133 lines (115 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import json
import sys
import thread
from base64 import b64encode
from twisted.internet import reactor
from pyipv8.controller import Controller
from pyipv8.gui import open_gui
from pyipv8.ipv8.REST.rest_manager import RESTManager
from pyipv8.ipv8.keyvault.crypto import ECCrypto
from pyipv8.ipv8_service import IPv8
import subprocess
try:
import tkinter as tk
except ImportError:
import Tkinter as tk
import socket
def get_open_port():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("",0))
s.listen(1)
port = s.getsockname()[1]
s.close()
return port
config = {
'address': '0.0.0.0',
'port': 8090,
'keys': [{
'alias': "discovery",
'generation': u"medium",
'file': u"keys/discovery.pem"
}],
'logger': {
'level': "INFO"
},
'walker_interval': 0.5,
'overlays': [
{
'class': 'DiscoveryCommunity',
'key': "discovery",
'walkers': [
{
'strategy': "RandomWalk",
'peers': 20,
'init': {
'timeout': 3.0
}
},
{
'strategy': "RandomChurn",
'peers': -1,
'init': {
'sample_size': 8,
'ping_interval': 10.0,
'inactive_time': 27.5,
'drop_time': 57.5
}
}
],
'initialize': {},
'on_start': [
('resolve_dns_bootstrap_addresses',)
]
}
]
}
try:
with open('property_to_key_mappings.json', 'r') as file:
json_file = json.load(file)
for property in json_file:
# with open("keys/" + property[1] + ".pem", 'r') as key:
# key_content = key.read()
config['keys'].append({
'alias': property[1],
'generation': u"medium",
'file': u"keys/" + property[1] + ".pem"
})
config['overlays'].append(
{
'class': 'BOBChainCommunity',
'key': property[1],
'walkers': [{
'strategy': "EdgeWalk",
'peers': 20,
'init': {
'edge_length': 4,
'neighborhood_size': 6,
'edge_timeout': 3.0
}
}],
'initialize': property[0],
'on_start': [('started',)]
}
)
except IOError:
with open('property_to_key_mappings.json', 'w') as file:
json.dump([], file)
# Start the IPv8 service
ipv8 = IPv8.__new__(IPv8)
controller = Controller(ipv8)
ipv8.__init__(config)
rest_manager = RESTManager(ipv8)
if len(sys.argv) > 1:
rest_manager.start(int(sys.argv[1]))
else:
rest_manager.start(14410)
#rest_manager.start(get_open_port())
root = tk.Tk()
root.geometry("900x900")
thread.start_new_thread(open_gui, (controller,root))
#subprocess.call(["python2", "main.py", "14411"])
thread.start_new_thread(open_gui, (controller,root))
root.mainloop()
# Start the Twisted reactor: this is the engine scheduling all of the
# asynchronous calls.
reactor.run()