2019-08-16 07:26:22 +08:00
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
from libp2p.crypto.keys import PrivateKey, PublicKey
|
2019-08-03 07:50:44 +08:00
|
|
|
from libp2p.peer.id import ID
|
|
|
|
from libp2p.security.secure_conn_interface import ISecureConn
|
|
|
|
|
|
|
|
|
2019-08-17 00:19:37 +08:00
|
|
|
class BaseSession(ISecureConn):
|
2019-08-03 07:50:44 +08:00
|
|
|
"""
|
|
|
|
``BaseSession`` is not fully instantiated from its abstract classes as it
|
|
|
|
is only meant to be used in clases that derive from it.
|
|
|
|
"""
|
|
|
|
|
2019-08-20 23:54:33 +08:00
|
|
|
local_peer: ID
|
|
|
|
local_private_key: PrivateKey
|
|
|
|
remote_peer_id: ID
|
|
|
|
remote_permanent_pubkey: PublicKey
|
|
|
|
|
2019-08-03 07:50:44 +08:00
|
|
|
def __init__(
|
2019-08-17 05:08:27 +08:00
|
|
|
self,
|
2019-08-24 05:43:36 +08:00
|
|
|
local_peer: ID,
|
|
|
|
local_private_key: PrivateKey,
|
2019-09-09 03:37:41 +08:00
|
|
|
initiator: bool,
|
2019-08-17 05:08:27 +08:00
|
|
|
peer_id: Optional[ID] = None,
|
2019-08-03 07:50:44 +08:00
|
|
|
) -> None:
|
2019-08-24 05:43:36 +08:00
|
|
|
self.local_peer = local_peer
|
|
|
|
self.local_private_key = local_private_key
|
2019-08-03 07:50:44 +08:00
|
|
|
self.remote_peer_id = peer_id
|
2019-08-16 07:26:22 +08:00
|
|
|
self.remote_permanent_pubkey = None
|
2019-09-09 03:37:41 +08:00
|
|
|
self.initiator = initiator
|
2019-08-03 08:41:29 +08:00
|
|
|
|
2019-08-03 07:50:44 +08:00
|
|
|
def get_local_peer(self) -> ID:
|
|
|
|
return self.local_peer
|
|
|
|
|
2019-08-16 07:26:22 +08:00
|
|
|
def get_local_private_key(self) -> PrivateKey:
|
2019-08-03 07:50:44 +08:00
|
|
|
return self.local_private_key
|
|
|
|
|
|
|
|
def get_remote_peer(self) -> ID:
|
|
|
|
return self.remote_peer_id
|
|
|
|
|
2019-08-16 07:26:22 +08:00
|
|
|
def get_remote_public_key(self) -> Optional[PublicKey]:
|
2019-08-03 07:50:44 +08:00
|
|
|
return self.remote_permanent_pubkey
|