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
|
#!/usr/bin/env python
# Both have a very small chance of occuring
from twisted.internet import reactor
from mesh import Mesh, MeshNode, packet_type, BYE, DATA
import sys
NUMNODES = 2
DELAY = 0.1
m = Mesh()
success = False
class TestMeshNode(MeshNode):
def newNode (self, data):
MeshNode.newNode (self, data)
print data + " joined"
if (data == failnode.name):
m.removeMeshNode(failnode)
n = MeshNode("joinnode", m)
m.addMeshNode(n)
m.connect_duplex (self, n, 1024, 50, 0.30)
if (data == "joinnode"):
global success
success = True
reactor.crash()
def lostNode (self, data):
MeshNode.lostNode (self, data)
print data + " lost"
n = TestMeshNode("node", m)
m.addMeshNode(n)
failnode = MeshNode("failnode", m)
m.addMeshNode(failnode)
# Connect all nodes to all others. 1024 bytes/s bandwidth, 50ms delay and 0%
# packet loss.. (bandwidth and delay aren't implemented just yet)
m.connect_full(1024, 50, 0.30)
reactor.run()
if not success:
print "FAILED"
exit(1)
print "SUCCESS"
exit(0)
|