bugfix
This commit is contained in:
parent
df645fbc86
commit
2315f8706a
@ -6,7 +6,7 @@ from appPublic.rsa import RSA
|
|||||||
from appPublic.rc4 import RC4
|
from appPublic.rc4 import RC4
|
||||||
from appPublic.uniqueID import getID
|
from appPublic.uniqueID import getID
|
||||||
|
|
||||||
import brotli
|
# import brotli
|
||||||
import zlib
|
import zlib
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
@ -90,6 +90,7 @@ class DataEncoder:
|
|||||||
|
|
||||||
def pack(self, peer_id, data):
|
def pack(self, peer_id, data):
|
||||||
pk = self.get_peer_pubkey(peer_id)
|
pk = self.get_peer_pubkey(peer_id)
|
||||||
|
print(peer_id, 'pk=', pk)
|
||||||
t, d = self.identify_datatype(data)
|
t, d = self.identify_datatype(data)
|
||||||
d, k = self.encode_data(pk, d)
|
d, k = self.encode_data(pk, d)
|
||||||
f = 'b%05ds%03ds' % (len(d), len(k))
|
f = 'b%05ds%03ds' % (len(d), len(k))
|
||||||
@ -101,15 +102,11 @@ class DataEncoder:
|
|||||||
pd += s
|
pd += s
|
||||||
self.pack_d = [t,d,k,s]
|
self.pack_d = [t,d,k,s]
|
||||||
origin_len = len(pd)
|
origin_len = len(pd)
|
||||||
pd = brotli.compress(pd)
|
pd = zlib.compress(pd)
|
||||||
pdz = zlib.compress(pd)
|
|
||||||
print('brotli lenght=%d, zlib length=%d, origin length=%d' % \
|
|
||||||
(len(pd), len(pdz), origin_len)
|
|
||||||
)
|
|
||||||
return pd
|
return pd
|
||||||
|
|
||||||
def unpack(self, peer_id, data):
|
def unpack(self, peer_id, data):
|
||||||
data = brotli.decompress(data)
|
data = zlib.decompress(data)
|
||||||
org_data = data
|
org_data = data
|
||||||
pk = self.get_peer_pubkey(peer_id)
|
pk = self.get_peer_pubkey(peer_id)
|
||||||
f = data[:18]
|
f = data[:18]
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
import sys
|
import sys
|
||||||
from brotli import compress, decompress
|
from brotli import compress, decompress
|
||||||
|
import zlib
|
||||||
|
|
||||||
def do(fn):
|
def do(fn):
|
||||||
with open(fn, 'rb') as f:
|
with open(fn, 'rb') as f:
|
||||||
b = f.read()
|
b = f.read()
|
||||||
c = compress(b)
|
c = compress(b)
|
||||||
d = decompress(c)
|
zc = zlib.compress(b)
|
||||||
print(fn,'\t',
|
print(fn,'\t',
|
||||||
float(len(c))/float(len(b)))
|
float(len(c))/float(len(b)), float(len(zc))/float(len(b)))
|
||||||
fns = sys.argv[1:]
|
fns = sys.argv[1:]
|
||||||
for fn in fns:
|
for fn in fns:
|
||||||
do(fn)
|
do(fn)
|
||||||
|
@ -2,18 +2,20 @@
|
|||||||
from appPublic.rsa import RSA
|
from appPublic.rsa import RSA
|
||||||
from appPublic.dataencoder import DataEncoder
|
from appPublic.dataencoder import DataEncoder
|
||||||
|
|
||||||
def get_prikey(id):
|
Nodes = {
|
||||||
prifile='prikey2.rsa'
|
}
|
||||||
if id=='node1':
|
|
||||||
prifile = 'prikey1.rsa'
|
def get_pubkey(id):
|
||||||
rsa = RSA()
|
node = Nodes.get(id)
|
||||||
prikey = rsa.read_privatekey(prifile)
|
return node.public_key
|
||||||
pubkey = rsa.create_publickey(prikey)
|
|
||||||
return pubkey
|
|
||||||
|
|
||||||
|
|
||||||
node1 = DataEncoder('node1', get_prikey, 'prikey1.rsa')
|
Nodes['node1'] = node1 = DataEncoder('node1', get_pubkey, 'prikey1.rsa')
|
||||||
node2 = DataEncoder('node2', get_prikey, 'prikey2.rsa')
|
Nodes['node2'] = node2 = DataEncoder('node2', get_pubkey, 'prikey2.rsa')
|
||||||
|
|
||||||
|
node1.set_peer_pubkey('node2', get_pubkey('node2'))
|
||||||
|
node2.set_peer_pubkey('node1', get_pubkey('node1'))
|
||||||
|
|
||||||
data1 = {
|
data1 = {
|
||||||
'a':'iy34ti3y42ti23t425g4',
|
'a':'iy34ti3y42ti23t425g4',
|
||||||
'b':100,
|
'b':100,
|
||||||
|
Loading…
Reference in New Issue
Block a user