Skip to content

Instantly share code, notes, and snippets.

@eklitzke
Created July 31, 2009 05:51
Show Gist options
  • Save eklitzke/159104 to your computer and use it in GitHub Desktop.
Save eklitzke/159104 to your computer and use it in GitHub Desktop.
def make_hdr(self, replyto=None, srcnode=None):
hdr = rucksack.interface.MsgHdr()
hdr.msgid = str(rucksack.util.rand64())
if replyto is not None:
hdr.replyto = replyto
if srcnode is not None:
hdr.srcnode = self.node
return hdr
def notify_membership(self, fd, events, ev):
"""Callback to send a membership notification.
This callback is scheduled as a persistent callback that creates a
transient callback to send an announce message when the socket is
writeable.
"""
def send_notification(fd, events, ev):
msg = rucksack.interface.JoinMsg()
msg.hdr.CopyFrom(self.make_hdr())
#msg.nodes = []
print 'sent!'
self.sock.sendall(msg.SerializeToString())
notify_timer = libevent.create_timer(self.notify_membership)
notify_timer.add_to_loop(self.JOIN_FREQ)
self.add_event(libevent.EV_WRITE, send_notification)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment