2019-04-30 15:09:05 +08:00
|
|
|
from libp2p.security.secure_transport_interface import ISecureTransport
|
|
|
|
from libp2p.security.secure_conn_interface import ISecureConn
|
|
|
|
|
|
|
|
|
2019-08-01 06:00:12 +08:00
|
|
|
class InsecureTransport(ISecureTransport):
|
2019-04-30 15:09:05 +08:00
|
|
|
def __init__(self, transport_id):
|
|
|
|
self.transport_id = transport_id
|
2019-05-02 01:54:19 +08:00
|
|
|
|
2019-04-30 15:09:05 +08:00
|
|
|
async def secure_inbound(self, conn):
|
|
|
|
"""
|
|
|
|
Secure the connection, either locally or by communicating with opposing node via conn,
|
|
|
|
for an inbound connection (i.e. we are not the initiator)
|
|
|
|
:return: secure connection object (that implements secure_conn_interface)
|
|
|
|
"""
|
|
|
|
insecure_conn = InsecureConn(conn, self.transport_id)
|
|
|
|
return insecure_conn
|
|
|
|
|
|
|
|
async def secure_outbound(self, conn, peer_id):
|
|
|
|
"""
|
|
|
|
Secure the connection, either locally or by communicating with opposing node via conn,
|
|
|
|
for an inbound connection (i.e. we are the initiator)
|
|
|
|
:return: secure connection object (that implements secure_conn_interface)
|
|
|
|
"""
|
|
|
|
insecure_conn = InsecureConn(conn, self.transport_id)
|
|
|
|
return insecure_conn
|
|
|
|
|
|
|
|
|
2019-08-01 06:00:12 +08:00
|
|
|
class InsecureConn(ISecureConn):
|
2019-04-30 15:09:05 +08:00
|
|
|
def __init__(self, conn, conn_id):
|
|
|
|
self.conn = conn
|
|
|
|
self.details = {}
|
|
|
|
self.details["id"] = conn_id
|
|
|
|
|
|
|
|
def get_conn(self):
|
|
|
|
"""
|
|
|
|
:return: connection object that has been made secure
|
|
|
|
"""
|
|
|
|
return self.conn
|
|
|
|
|
|
|
|
def get_security_details(self):
|
|
|
|
"""
|
|
|
|
:return: map containing details about the connections security
|
|
|
|
"""
|
|
|
|
return self.details
|