Esempio n. 1
0
def recursiveLookup(STS, nodeTuple):
    global recursiveNodes
    results = request.KademliaProtocol(STS).findNode(
        packet.xxhashUser('netsec41'),
        (packet.constructIP(nodeTuple[0]), nodeTuple[1]))
    time.sleep(3)
    nodeData = message.Messages().returnResponse(results)
    if nodeData is not None:
        message.Messages().removeRequest(results)
        for key, value in RT.PopulateRoutingTable(nodeData).items():
            recursiveNodes[key] = value
    else:
        message.Messages().removeRequest(results)
Esempio n. 2
0
    def Kclosest(self, nodeID):
        Kbuckets = self.GetRouteTable()
        KcloseNodes = []
        keySelected = None
        keySelf = format(packet.xxhashUser('netsec41'), '016b')
        node = format(nodeID, '016b')

        for key, v in Kbuckets.items():

            if node.startswith(key):
                keySelected = key
                for val in v:
                    if val and val not in KcloseNodes:
                        KcloseNodes.append(val)
                        if len(KcloseNodes) >= self.k:
                            return KcloseNodes

        if not keySelected:
            for _, v in Kbuckets.items():
                for val in v:
                    if val and val not in KcloseNodes:
                        KcloseNodes.append(val)
                        if len(KcloseNodes) >= self.k:
                            return KcloseNodes

        else:
            KcloseNodes = self.findClosest(keySelected[0:len(keySelected) - 1], Kbuckets, KcloseNodes)
            if KcloseNodes == self.k:
                return KcloseNodes
            else:
                for _, v in Kbuckets.items():
                    for val in v:
                        if val and val not in KcloseNodes:
                            KcloseNodes.append(val)
                            if len(KcloseNodes) >= self.k:
                                return KcloseNodes
        return KcloseNodes
Esempio n. 3
0
 def __init__(self, STS):
     self.nodeID = packet.xxhashUser('netsec41')
     self.nonce = packet.nonceGen()
     self.STS = STS
Esempio n. 4
0
 def __init__(self, STS, k=4):
     self.RoutingTable = OrderedDict()
     self.ownID = packet.xxhashUser('netsec41')
     self.k = k
     self.STS = STS
Esempio n. 5
0
if __name__ == '__main__':
    try:
        threads = []
        threads_inner = []

        print('=== DHT NODE STARTED ON ' + localIP + ':' + str(localPort) +
              ' ===')

        # start the server thread
        th1 = Thread(target=serverProtocol, args=[STS])
        threads.append(th1)
        th1.start()

        # recursive lookup thread, initially to build the routing table
        result = request.KademliaProtocol(STS).findNode(
            packet.xxhashUser('netsec41'), ('172.18.0.252', 1337))
        th2 = Thread(target=selfLookup, args=[STS, threads_inner, result])
        threads.append(th2)
        th2.start()

        # wait for the recursive lookup to complete
        th2.join()
        threads.remove(th2)

        # initiate the thread to store data onto the nodes
        th3 = Thread(target=storeOnNodes, args=[STS])
        threads.append(th3)
        th3.start()

        # initiate the thread to update current certificate status
        th4 = Thread(target=updateCertificateStatus, args=[STS])