示例#1
0
def startPD():
    p=Peer(uid=uuid1().hex, name='anon',addr='127.0.0.1')
    p_l=PeerContainer(refAdd, refDel)
    i=Inducter(('224.0.2.38',8999))
    reactor.listenMulticast(8999,i)
    h=MessageHandler(p, i.broadcast, p_l)
    i.addHandler(h.handle)
示例#2
0
class PDModule(object):
	def __init__(self, mcast_addr, name, peer_container):
		peer_obj=Peer(uid=uuid1().hex, name=name, addr='127.0.0.1')
		self.mcast_iface=Inducter(mcast_addr)
		reactor.listenMulticast(mcast_addr[1], self.mcast_iface)
		self.m_handler=MessageHandler(peer_obj, (lambda x:x) , peer_container)
		self.m_handler.enabled=False

	def setEnable(self, enable):
		if(enable):
			logging.info('Peer Discovery is enabled')
			self.m_handler.setOutputStream(self.mcast_iface.broadcast)
			self.mcast_iface.addHandler(self.m_handler.handle)
			#Don't do anything if its already enabled
			if not self.m_handler.enabled:
				#Reset hook gap
				self.m_handler.resetAll()
		else:
			logging.info('Disabling Peer Discovery')
			try:
				self.m_handler.hook_ID.cancel()
			except:
				pass
			self.m_handler.unhook()
			self.m_handler.enabled=False
			self.m_handler.setOutputStream((lambda x:x))
			self.mcast_iface.addHandler(None)
示例#3
0
#!/usr/bin/env python2

from LPDoL.multicast import Inducter
from LPDoL.handler import MessageHandler
from LPDoL.common import *
from uuid import uuid1
from twisted.internet import reactor


def cb(x):
    print x


if __name__ == '__main__':
    p = Peer(uid=uuid1().hex, name='anon', addr='127.0.0.1')
    p_l = PeerContainer(cb, cb)
    i = Inducter(('224.0.2.38', 8999))
    reactor.listenMulticast(8999, i)
    h = MessageHandler(p, i.broadcast, p_l)
    i.addHandler(h.handle)
    reactor.run()
示例#4
0
文件: discover.py 项目: vasuman/FiSH
#!/usr/bin/env python2

from LPDoL.multicast import Inducter
from LPDoL.handler import MessageHandler
from LPDoL.common import *
from uuid import uuid1
from twisted.internet import reactor


def cb(x):
    print x


if __name__ == "__main__":
    p = Peer(uid=uuid1().hex, name="anon", addr="127.0.0.1")
    p_l = PeerContainer(cb, cb)
    i = Inducter(("224.0.2.38", 8999))
    reactor.listenMulticast(8999, i)
    h = MessageHandler(p, i.broadcast, p_l)
    i.addHandler(h.handle)
    reactor.run()
示例#5
0
	def __init__(self, mcast_addr, name, peer_container):
		peer_obj=Peer(uid=uuid1().hex, name=name, addr='127.0.0.1')
		self.mcast_iface=Inducter(mcast_addr)
		reactor.listenMulticast(mcast_addr[1], self.mcast_iface)
		self.m_handler=MessageHandler(peer_obj, (lambda x:x) , peer_container)
		self.m_handler.enabled=False