<commit_before>from twisted.internet import reactor
from twisted.internet.protocol import DatagramProtocol
from twisted.internet.task import LoopingCall

from zmqproto.zre import ZreProtocol
from socket import SOL_SOCKET, SO_BROADCAST

class ZreNode(DatagramProtocol):
    def __init__(self, ipaddr):
        self.proto = ZreProtocol(ipaddr)
        self.peers = {}
        reactor.listenMulticast(5670, self, listenMultiple=True)

    def startProtocol(self):
        # Set the TTL>1 so multicast will cross router hops:
        self.transport.setTTL(5)
        # Join a specific multicast group:
        #self.transport.joinGroup("172.16.58.3")
        self.loopObj = LoopingCall(self.sendHeartBeat)
        self.loopObj.start(10, now=True)

    def sendHeartBeat(self):
        #print self.transport, dir(self.transport)
        #print self.transport.socket, dir(self.transport.socket)
        print "* heartbeat"
        self.transport.socket.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
        self.transport.write(self.proto.buildBeacon(), ('127.255.255.255', 5670))

    def datagramReceived(self, data, (host, port)):
        uuid, _port = self.proto.parseBeacon(data)
        if not uuid == self.proto.uuid:
            if not uuid in self.peers:
                self.peers[uuid] = [_port, host, port]
                print "[%s] beacon id %s port %s [%s:%d]" % (self.proto.uuid, uuid, _port, host, port)


if __name__ == '__main__':
    node1 = ZreNode('127.0.0.1')
    node2 = ZreNode('127.0.0.2')
    node3 = ZreNode('127.0.0.3')
    reactor.run()<commit_msg>Remove some debug prints.<commit_after>from twisted.internet import reactor
from twisted.internet.protocol import DatagramProtocol
from twisted.internet.task import LoopingCall

from zmqproto.zre import ZreProtocol
from socket import SOL_SOCKET, SO_BROADCAST

class ZreNode(DatagramProtocol):
    def __init__(self, ipaddr):
        self.proto = ZreProtocol(ipaddr)
        self.peers = {}
        reactor.listenMulticast(5670, self, listenMultiple=True)

    def startProtocol(self):
        # Set the TTL>1 so multicast will cross router hops:
        self.transport.setTTL(5)
        # Join a specific multicast group:
        #self.transport.joinGroup("172.16.58.3")
        self.loopObj = LoopingCall(self.sendHeartBeat)
        self.loopObj.start(10, now=True)

    def sendHeartBeat(self):
        self.transport.socket.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
        self.transport.write(self.proto.buildBeacon(), ('127.255.255.255', 5670))

    def datagramReceived(self, data, (host, port)):
        uuid, _port = self.proto.parseBeacon(data)
        if not uuid == self.proto.uuid:
            if not uuid in self.peers:
                self.peers[uuid] = [_port, host, port]
                print "[%s] beacon id %s port %s [%s:%d]" % (self.proto.uuid, uuid, _port, host, port)


if __name__ == '__main__':
    node1 = ZreNode('127.0.0.1')
    node2 = ZreNode('127.0.0.2')
    node3 = ZreNode('127.0.0.3')
    reactor.run()
{'fraction_non_alphanumeric': 0.12125249833444371, 'fraction_numerical': 0.03597601598934044, 'mean_word_length': 2.9933510638297873, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 10, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '71693', 'n_tokens_mistral': 1071, 'n_tokens_neox': 987, 'n_words': 222}