本文整理汇总了Python中btconn.BTConnection.get_his_id方法的典型用法代码示例。如果您正苦于以下问题:Python BTConnection.get_his_id方法的具体用法?Python BTConnection.get_his_id怎么用?Python BTConnection.get_his_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类btconn.BTConnection
的用法示例。
在下文中一共展示了BTConnection.get_his_id方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from btconn import BTConnection [as 别名]
# 或者: from btconn.BTConnection import get_his_id [as 别名]
class ConnecterConnection:
def __init__(self,port):
self.s = BTConnection('localhost',port)
self.s.read_handshake_medium_rare()
self.connection = EncrypterConnection(self.s.get_his_id())
def get_my_id(self):
return self.s.get_my_id()
def get_unauth_peer_id(self):
return self.s.get_his_id()
def is_locally_initiated(self):
return True
def send_message(self,msg):
self.s.send(msg)
def get_message(self):
return self.s.recv()
def set_permid(self,x):
pass
def set_auth_peer_id(self,x):
pass
def close(self):
self.s.close()
示例2: _test_response1
# 需要导入模块: from btconn import BTConnection [as 别名]
# 或者: from btconn.BTConnection import get_his_id [as 别名]
def _test_response1(self,ss,gen_resp1,good):
print >>sys.stderr,"test: myserver running:",gen_resp1
conn, addr = ss.accept()
s = BTConnection('',0,conn)
s.read_handshake_medium_rare()
# Read challenge
msg = s.recv()
self.testcase.assert_(msg[0] == CHALLENGE)
randomB = bdecode(msg[1:])
self.testcase.assert_(type(randomB) == StringType)
self.testcase.assert_(len(randomB) == random_size)
[randomA,resp1_data] = gen_resp1(randomB,s.get_his_id())
s.send(resp1_data)
if good:
# Read response2
msg = s.recv()
self.testcase.assert_(msg[0] == RESPONSE2)
self.check_response2(msg[1:],randomA,randomB,s.get_my_id())
# the connection should be intact, so this should not throw an
# exception:
time.sleep(5)
s.send('bla')
s.close()
else:
time.sleep(5)
# the other side should not our bad RESPONSE1 this and close the
# connection
msg = s.recv()
self.testcase.assert_(len(msg)==0)
s.close()
示例3: _test_bad_response2
# 需要导入模块: from btconn import BTConnection [as 别名]
# 或者: from btconn.BTConnection import get_his_id [as 别名]
def _test_bad_response2(self, gen_resp2_func):
print >>sys.stderr, time.asctime(), "-", "test: bad response2", gen_resp2_func
s = BTConnection("localhost", self.hisport)
s.read_handshake()
[rB, chal_data] = self.create_good_challenge()
s.send(chal_data)
resp1_data = s.recv()
self.assert_(resp1_data[0] == RESPONSE1)
resp1_dict = self.check_response1(resp1_data[1:], rB, s.get_my_id())
resp2_data = gen_resp2_func(rB, resp1_dict, s.get_his_id())
s.send(resp2_data)
time.sleep(5)
# the other side should not like this and close the connection
msg = s.recv()
self.assert_(len(msg) == 0)
s.close()
示例4: subtest_good_challenge_response2
# 需要导入模块: from btconn import BTConnection [as 别名]
# 或者: from btconn.BTConnection import get_his_id [as 别名]
def subtest_good_challenge_response2(self):
"""
test good challenge and response2 messages
"""
print >>sys.stderr, time.asctime(), "-", "test: good challenge/response"
s = BTConnection("localhost", self.hisport)
s.read_handshake()
[rB, chal_data] = self.create_good_challenge()
s.send(chal_data)
resp1_data = s.recv()
self.assert_(resp1_data[0] == RESPONSE1)
resp1_dict = self.check_response1(resp1_data[1:], rB, s.get_my_id())
resp2_data = self.create_good_response2(rB, resp1_dict, s.get_his_id())
s.send(resp2_data)
time.sleep(10)
# the other side should not have closed the connection, as
# this is all valid, so this should not throw an exception:
s.send("bla")
s.close()
示例5: __init__
# 需要导入模块: from btconn import BTConnection [as 别名]
# 或者: from btconn.BTConnection import get_his_id [as 别名]
class OLConnection:
def __init__(self,my_keypair,hostname,port,opensock=None,mylistenport=481,myoversion=None):
""" If opensock is not None, we assume this is a connection we
accepted, and he initiates the Challenge/Response
"""
self.my_keypair = my_keypair
self.b = BTConnection(hostname,port,opensock,mylistenport=mylistenport,myoversion=myoversion)
if opensock:
self.b.read_handshake_medium_rare()
# Read challenge
msg = self.b.recv()
assert(msg[0] == CHALLENGE)
randomB = bdecode(msg[1:])
[randomA,resp1_data] = self.create_good_response1(randomB,self.b.get_his_id())
self.b.send(resp1_data)
# Read response2
msg = self.b.recv()
assert(msg[0] == RESPONSE2)
else:
self.b.read_handshake()
[rB,chal_data] = self.create_good_challenge()
self.b.send(chal_data)
resp1_data = self.b.recv()
if DEBUG:
print >>sys.stderr,"olconn: recv",len(resp1_data),"bytes"
resp1_dict = bdecode(resp1_data[1:])
resp2_data = self.create_good_response2(rB,resp1_dict,self.b.get_his_id())
self.b.send(resp2_data)
if DEBUG:
print >>sys.stderr,"olconn: sent",len(resp2_data),"bytes"
def get_my_fake_listen_port(self):
return self.b.get_my_fake_listen_port()
#
# Cut 'n paste from TestPermIDs
#
def create_good_challenge(self):
r = "".zfill(cr_random_size)
return [r,self.create_challenge_payload(r)]
def create_good_response2(self,rB,resp1_dict,hisid):
resp2 = {}
resp2['certB'] = str(self.my_keypair.pub().get_der())
resp2['A'] = hisid
sig_list = [rB,resp1_dict['rA'],hisid]
sig_data = bencode(sig_list)
sig_hash = sha(sig_data).digest()
sig_asn1 = str(self.my_keypair.sign_dsa_asn1(sig_hash))
resp2['SB'] = sig_asn1
return self.create_response2_payload(resp2)
def create_challenge_payload(self,r):
return CHALLENGE+bencode(r)
def create_response2_payload(self,dict):
return RESPONSE2+bencode(dict)
#
# Cut 'n paste from TestPermIDResponse1
#
def create_good_response1(self,rB,hisid):
resp1 = {}
resp1['certA'] = str(self.my_keypair.pub().get_der())
resp1['rA'] = "".zfill(cr_random_size)
resp1['B'] = hisid
sig_list = [resp1['rA'],rB,hisid]
sig_data = bencode(sig_list)
sig_hash = sha(sig_data).digest()
sig_asn1 = str(self.my_keypair.sign_dsa_asn1(sig_hash))
resp1['SA'] = sig_asn1
return [resp1['rA'],self.create_response1_payload(resp1)]
def create_response1_payload(self,dict):
return RESPONSE1+bencode(dict)
def send(self,data):
""" send length-prefixed message """
self.b.send(data)
def recv(self):
""" received length-prefixed message """
return self.b.recv()
def close(self):
self.b.close()