コード例 #1
0
ファイル: dummy_network.py プロジェクト: kyonetca/P2PDNS
 def send_message(self, msg, dest):
     node_name = dest.IPAddr + "_" + str(dest.ctrlPort)
     dest_path = self.root_mailbox_path + node_name + "/" + str(
         hash_util.generate_random_key())
     if msg.service == SERVICE_INTERNAL:
         pass
         #print "sending " + msg.get_content("type") + " to: " + dest_path
     outfile = file(dest_path, "w+")
     outfile.write(msg.serialize())
     outfile.close()
コード例 #2
0
ファイル: filesystem_service.py プロジェクト: kyonetca/P2PDNS
 def store(self, filename,segment_size=128):
     segment_ids = []
     segments = []
     with open(filename, "rb") as f:
         byte = f.read(segment_size)
         while byte:
             newid = hash_util.generate_random_key().key
             segment_ids.append(newid)
             segments.append(byte)
             byte = f.read(segment_size)
     keyfile = "KEYFILE\n"+filename+"\n"+reduce(lambda x,y: x+"\n"+y,segment_ids)
     keyfile_hash = hash_util.hash_str(filename)
     keyfile_message = shelver.Database_Message(self.owner,keyfile_hash, "FileSystem", "PUT")
     keyfile_message.add_content("file_contents",keyfile)
     self.send_message(keyfile_message,None)
     number_of_chunks = len(segments)
     for i in range(0,number_of_chunks):
         chunkfile_message = shelver.Database_Message(self.owner,hash_util.Key(segment_ids[i]), "FileSystem", "PUT")
         actual_contents = str(keyfile_hash)+"\n"+segments[i]
         chunkfile_message.add_content("file_contents",actual_contents)
         self.send_message(chunkfile_message,None)
コード例 #3
0
ファイル: minerServ.py プロジェクト: BrendanBenshoof/P2PDNS
 def mine(self, transfers, award):
     done = False
     newblock = Block()
     while not done:
         curr = self.currentBlock
         # print curr
         newblock = Block()
         newblock.lasthash = curr.gethashval()
         newblock.blockid = str(int(curr.blockid) + 1)
         newblock.award = award
         newblock.transactions = transfers
         newblock.time = str(time.time())
         newblock.nonce = hash_util.generate_random_key().key
         hashval = int(newblock.gethashval(), 16)
         print float(hashval), difficulty
         if hashval < difficulty:
             break
         else:
             time.sleep(0.01)
             print "fail"
     print "new block"
     self.offer(newblock)
     return str(newblock)
コード例 #4
0
ファイル: solo-miner.py プロジェクト: kyonetca/P2PDNS
#hash of Last Block|blockid|Exchanges|declaration|timestamp|nonce
#64 bit int
#hash of last block = 160 bit hash of the previous block
#Exchanges = <Domain,Newowner>sig(oldowner)
#Declaration = <Domain, newowner>
#timestamp = unix epoc time
#none =

# '|' is the divider between sections
# '+' is the divider between Exchanges
#EXAMPLE
"""
test = hash_util.hash_str("TEST")
print test
test_user = sec_service.SecNodeInfo.generate_new("Brendan")
print test_user.gen_secret(False)
"""
difficulty = 2**140

test = """0x0000000000000000000000000000000000000000|0||<test,Brendan:0x540be95c12e72a28c32388994ff0efb12ac63ca7:0x800b400ed966fcc0d4807adf5e884f1ed6af227aaeb00c463ebdf473d4da1b9bde466a9d155df80dbc565575a5130344691425d0f705c88514d77912f3fd339d?0x10001>|1384540375.4590001|"""

nonce = hash_util.generate_random_key()
newhash = hash_util.hash_str(test + str(nonce))
while newhash.toint() > difficulty:
    print
    nonce = hash_util.generate_random_key()
    newhash = hash_util.hash_str(test + str(nonce))
print ""
print nonce
print newhash
コード例 #5
0
ファイル: solo-miner.py プロジェクト: BrendanBenshoof/P2PDNS
#Exchanges = <Domain,Newowner>sig(oldowner)
#Declaration = <Domain, newowner>
#timestamp = unix epoc time
#none = 

# '|' is the divider between sections
# '+' is the divider between Exchanges
#EXAMPLE
"""
test = hash_util.hash_str("TEST")
print test
test_user = sec_service.SecNodeInfo.generate_new("Brendan")
print test_user.gen_secret(False)
"""
difficulty = 2**140


test="""0x0000000000000000000000000000000000000000|0||<test,Brendan:0x540be95c12e72a28c32388994ff0efb12ac63ca7:0x800b400ed966fcc0d4807adf5e884f1ed6af227aaeb00c463ebdf473d4da1b9bde466a9d155df80dbc565575a5130344691425d0f705c88514d77912f3fd339d?0x10001>|1384540375.4590001|"""


nonce = hash_util.generate_random_key()
newhash = hash_util.hash_str(test+str(nonce))
while newhash.toint() > difficulty:
	print 
	nonce = hash_util.generate_random_key()
	newhash = hash_util.hash_str(test+str(nonce))
print ""
print nonce
print newhash