-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPeersManager.py
56 lines (38 loc) · 1.29 KB
/
PeersManager.py
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
from pyactor.context import set_context, create_host, sleep, shutdown, interval, later, Host, serve_forever
import Tracker
import Sequencer
import User
if __name__ == '__main__':
set_context()
messages = {1:["ARNAU","H","E","L","L","O"], 2:["PAU","W","O","R","L","D"] , 3:["SD","Lamport oh yeah!"], 4:["TASK2"]}
users = 5
usersProxies = []*users
#User Host
h = create_host('http://127.0.0.1:1240')
#Tracker Host
host = h.lookup_url('http://127.0.0.1:1220', Host)
tracker = host.lookup_url('http://127.0.0.1:1220/TrackerID', Tracker.Tracker)
#Sequencer Host
host2 = h.lookup_url('http://127.0.0.1:1230', Host)
for val in range(1,users):
sleep(0.1)
user = h.spawn("user" + str(val), User.User)
user.joinTracker(tracker,h)
user.setID(val)
user.setHosts(h,host2)
user.setTracker(tracker)
usersProxies.append(user)
user.init_start(h)
for val in range(1,users):
sleep(0.3)
ms = messages.get(val)
for m in ms:
usersProxies[val-1].multicast(m)
#usersProxies[val-1].multicastLamport(m)
sleep(30)
for user in usersProxies:
sleep(0.1)
user.process_msg()
#user.process_msg_Lamport()
sleep(1)
serve_forever()