Esempio n. 1
0
def install_package(path):
    import pymultihash as pmh
    os.chdir(path)
    paths = []
    for root, dir, files in os.walk("."):
            for item in files:
                if(len(item)>3 and item[-3:]==".py"):
                    path = root+"/"+item
                    hval = None
                    with open(path,"r") as fp:
                        data = fp.read()
                        hval = pmh.genHash(data,0x12)
                    paths.append((hval,path))
    cert = "\n".join(map(lambda x: " ".join(x),paths))
    certhash = pmh.genHash(cert,0x12)
    hashed_cert = certhash+"\n"+cert


    working_path = os.path.join(cachePath,certhash)
    #print("Working Path",working_path)
    ensure(working_path)
    with open(os.path.join(working_path,"certfile.txt"),"w") as fp:
        fp.write(hashed_cert)
    for h, fname in paths:
        dest = os.path.join(working_path,fname)
        dirname = os.path.dirname(dest)
        ensure(dirname)
        with open(fname,"r") as read_fp:
            with open(dest,"w") as write_fp:
                write_fp.write(read_fp.read())
    print("Package Name is:")
    print(certhash)
Esempio n. 2
0
def generateBloomFilter(wordlist):
    f = 0
    j = 0
    for w in wordlist:
        hashInt = 0
        hashVal = pmh.genHash(w, 0x12)
        for i in range(0, 10):
            try:
                tmpInt = 2**256-1
                for j in range(0,10):
                    tmpInt &= pmh.parseHash(hashVal)
                    hashVal = pmh.genHash(hashVal, 0x12)
                hashInt = (hashInt << 256) | tmpInt

            except Exception as e:
                print("error ",e)
                print(hashVal, w, i, j, len(wordlist))
            hashVal = pmh.genHash(hashVal, 0x12)
        f |= hashInt

        j += 1
    return f
Esempio n. 3
0
def generateBloomFilter(wordlist):
    f = 0
    j = 0
    for w in wordlist:
        hashInt = 0
        hashVal = pmh.genHash(w, 0x12)
        for i in range(0, 10):
            try:
                tmpInt = 2**256 - 1
                for j in range(0, 10):
                    tmpInt &= pmh.parseHash(hashVal)
                    hashVal = pmh.genHash(hashVal, 0x12)
                hashInt = (hashInt << 256) | tmpInt

            except Exception as e:
                print("error ", e)
                print(hashVal, w, i, j, len(wordlist))
            hashVal = pmh.genHash(hashVal, 0x12)
        f |= hashInt

        j += 1
    return f
Esempio n. 4
0
    peerPool = list(filter(lambda x: net.ping("UrDHT", x),
                           peerPool))  #filter only living bootstrap peers

    path = config["publicAddr"]
    if len(path) == 0 and len(peerPool) > 0:
        random_peer = random.choice(peerPool)
        pubip = net.getIP("UrDHT", random_peer)
        path = "http://%s:%d/" % (pubip, port)
    else:
        if path[-1] != "/":
            path += "/"
        if path[0:4] != "http":
            path = "http://" + path

    hashid = genHash(path, 0x12)

    myPeerInfo = util.PeerInfo(hashid, path, loc)

    logic = LogicClass.DHTLogic(myPeerInfo, "UrDHT")

    net.setup(logic, data)

    logic.setup(net, data)
    clientPeers = [json.loads(str(myPeerInfo))]
    if len(peerPool) > 0:
        strings = map(str, peerPool)
        clientPeers = json.loads("[%s]" % ",".join(strings))
    myClient = client.UrDHTClient("UrDHT", clientPeers)

    logic.join(peerPool)
Esempio n. 5
0
 def hash(self, string):
     return pmh.genHash(string, 0x12)
Esempio n. 6
0
You have left the publicAddr property in config.json empty and there are no
bootstraps to discover your external IP address for you.
You either:
    - Did not provide bootstraps
    - Cannot connect to any bootstraps (either they are offline or you are)

To fix this:
    - Figure out your external IP and provide it in config.json
    - If you are testing, you can use localhost as your ip
    - Make sure your internet is working
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
""")
        sys.exit()


    hashid = genHash(path,0x12)


    myPeerInfo = util.PeerInfo(hashid,path, loc)


    logic = LogicClass.DHTLogic(myPeerInfo,"UrDHT")

    net.setup(logic,data)

    logic.setup(net,data)
    clientPeers = [json.loads(str(myPeerInfo))]
    if len(peerPool) > 0:
        strings = map(str,peerPool)
        clientPeers = json.loads("[%s]"%",".join(strings))
    myClient = client.UrDHTClient("UrDHT",clientPeers)
Esempio n. 7
0
	def hash(self, string):
		return pmh.genHash(string,0x12)
Esempio n. 8
0
def wordInFilter(bloomInt, testWord):
    hashVal = pmh.genHash(testWord, 0x12)
    hashInt = pmh.parseHash(hashVal)
    return (bloomInt & hashInt) == hashInt
Esempio n. 9
0
def wordInFilter(bloomInt, testWord):
    hashVal = pmh.genHash(testWord, 0x12)
    hashInt = pmh.parseHash(hashVal)
    return (bloomInt & hashInt) == hashInt