예제 #1
0
thisPeer = Peer(args.name, args.IP, args.port, args.limit)
thisPeer.addResource(args.name, args.name + ' is interactive peer')

while True:
	do = input()

	# PEERS
	match = re.match("plist", do)
	if match:
		pprint.pprint(thisPeer.listPeers())
		continue

	match = re.match("hello", do)
	if match:
		thisPeer.multicast()
		thisPeer.startListeningForMulticast()
		thisPeer.startFindingNeighbours()
		thisPeer.startLookingForDeadNeighbours()
		continue

	match = re.match(r"hello\s((\d+\.\d+\.\d+\.\d+\:\d+)|localhost\:\d+)", do)
	if match:
		thisPeer.sayHello(match.group(1))
		thisPeer.multicast()
		thisPeer.startListeningForMulticast()
		thispeer.startFindingNeighbours()
		thisPeer.startLookingForDeadNeighbours()
		continue

예제 #2
0
파일: setup.py 프로젝트: Shne/P2PP
#!/usr/bin/python3
from peer import Peer
import random
import argparse

parser = argparse.ArgumentParser(description='Setup Script')
parser.add_argument('-peers', type=int, help='Number of peers to set up', default=30)
parser.add_argument('-late', type=float, help='Artificial Latency in RPC requests', default=.0)
args = parser.parse_args()
numberOfPeers = args.peers

names = ['P'+str(x) for x in range(numberOfPeers)]
IP = 'localhost'
ports = [10000+x for x in range(numberOfPeers)]


for (i,name) in enumerate(names):
	limit = 3
	while random.choice([True, True, True, False]):
		limit += 1
	peer = Peer(name, IP, ports[i], str(limit), args.late)
	peer.addResource(name, name + " iz best peer")
	peer.multicast()
	peer.startListeningForMulticast()
	peer.startFindingNeighbours()
	peer.startLookingForDeadNeighbours()
	peer.startSendingCoverTraffic()

input('>')