Introduce basic unreliability
This commit is contained in:
parent
f00c382ed5
commit
c485a39fb5
|
@ -1,6 +1,7 @@
|
||||||
# Sync protocol PoC
|
# Sync protocol PoC
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import random
|
||||||
import sync_pb2
|
import sync_pb2
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -32,16 +33,22 @@ class NetworkSimulator():
|
||||||
self.time = 0
|
self.time = 0
|
||||||
self.queue = {}
|
self.queue = {}
|
||||||
self.peers = {}
|
self.peers = {}
|
||||||
|
# XXX: Assuming nodes are offline most of the time
|
||||||
|
# This is different types of nodes, not global
|
||||||
|
self.reliability = 0.5
|
||||||
|
|
||||||
def tick(self):
|
def tick(self):
|
||||||
if self.time in self.queue:
|
if self.time in self.queue:
|
||||||
# XXX: Should sender be here?
|
# XXX: Should sender be here?
|
||||||
for sender, receiver, msg in self.queue[self.time]:
|
for sender, receiver, msg in self.queue[self.time]:
|
||||||
# NOTE: Assumes 100% reliability
|
if random.random() < self.reliability:
|
||||||
receiver.on_receive(sender, msg)
|
print "*** message ok", sender.name, "->", receiver.name
|
||||||
print ""
|
receiver.on_receive(sender, msg)
|
||||||
print "tick", self.time + 1
|
else:
|
||||||
print "-----------"
|
print "*** message dropped", sender.name, "->", receiver.name
|
||||||
|
#print ""
|
||||||
|
#print "tick", self.time + 1
|
||||||
|
#print "-----------"
|
||||||
for n in self.nodes:
|
for n in self.nodes:
|
||||||
n.tick()
|
n.tick()
|
||||||
self.time += 1
|
self.time += 1
|
||||||
|
@ -225,7 +232,7 @@ def new_ack_record(id):
|
||||||
# Mocking
|
# Mocking
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
def run(steps=4):
|
def run(steps=10):
|
||||||
n = NetworkSimulator()
|
n = NetworkSimulator()
|
||||||
|
|
||||||
a = Node("A", n)
|
a = Node("A", n)
|
||||||
|
@ -261,8 +268,8 @@ def run(steps=4):
|
||||||
peer.append_message(rec)
|
peer.append_message(rec)
|
||||||
|
|
||||||
n.tick()
|
n.tick()
|
||||||
a.print_sync_state()
|
#a.print_sync_state()
|
||||||
b.print_sync_state()
|
#b.print_sync_state()
|
||||||
|
|
||||||
acc = "\n"
|
acc = "\n"
|
||||||
for _, msg in a.messages.items():
|
for _, msg in a.messages.items():
|
||||||
|
@ -305,7 +312,6 @@ run()
|
||||||
# For any given (data) group, a device can decide
|
# For any given (data) group, a device can decide
|
||||||
# if they want to share or not with a peer.
|
# if they want to share or not with a peer.
|
||||||
|
|
||||||
|
|
||||||
# TODO: ACK should also be share policy
|
# TODO: ACK should also be share policy
|
||||||
# XXX: Encode offline mostly
|
# XXX: Encode offline mostly
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue