mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
Move base implementations into BaseSession
This commit is contained in:
@ -15,18 +15,35 @@ class BaseSession(ISecureConn, IRawConnection):
|
|||||||
) -> None:
|
) -> None:
|
||||||
self.local_peer = transport.local_peer
|
self.local_peer = transport.local_peer
|
||||||
self.local_private_key = transport.local_private_key
|
self.local_private_key = transport.local_private_key
|
||||||
self.insecure_conn = conn
|
self.conn = conn
|
||||||
self.remote_peer_id = peer_id
|
self.remote_peer_id = peer_id
|
||||||
self.remote_permanent_pubkey = b""
|
self.remote_permanent_pubkey = b""
|
||||||
|
|
||||||
# TODO clean up how this is passed around?
|
# TODO clean up how this is passed around?
|
||||||
@property
|
@property
|
||||||
def initiator(self) -> bool:
|
def initiator(self) -> bool:
|
||||||
return self.insecure_conn.initiator
|
return self.conn.initiator
|
||||||
|
|
||||||
# TODO clean up how this is passed around?
|
# TODO clean up how this is passed around?
|
||||||
def next_stream_id(self) -> int:
|
def next_stream_id(self) -> int:
|
||||||
return self.insecure_conn.next_stream_id()
|
return self.conn.next_stream_id()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def writer(self):
|
||||||
|
return self.conn.writer
|
||||||
|
|
||||||
|
@property
|
||||||
|
def reader(self):
|
||||||
|
return self.conn.reader
|
||||||
|
|
||||||
|
async def write(self, data: bytes) -> None:
|
||||||
|
await self.conn.write(data)
|
||||||
|
|
||||||
|
async def read(self) -> bytes:
|
||||||
|
return await self.conn.read()
|
||||||
|
|
||||||
|
def close(self) -> None:
|
||||||
|
self.conn.close()
|
||||||
|
|
||||||
def get_local_peer(self) -> ID:
|
def get_local_peer(self) -> ID:
|
||||||
return self.local_peer
|
return self.local_peer
|
||||||
|
|||||||
@ -6,19 +6,7 @@ from libp2p.security.secure_conn_interface import ISecureConn
|
|||||||
|
|
||||||
|
|
||||||
class InsecureSession(BaseSession):
|
class InsecureSession(BaseSession):
|
||||||
@property
|
pass
|
||||||
def writer(self):
|
|
||||||
return self.insecure_conn.writer
|
|
||||||
|
|
||||||
@property
|
|
||||||
def reader(self):
|
|
||||||
return self.insecure_conn.reader
|
|
||||||
|
|
||||||
async def write(self, data: bytes) -> None:
|
|
||||||
await self.insecure_conn.write(data)
|
|
||||||
|
|
||||||
async def read(self) -> bytes:
|
|
||||||
return await self.insecure_conn.read()
|
|
||||||
|
|
||||||
|
|
||||||
class InsecureTransport(BaseSecureTransport):
|
class InsecureTransport(BaseSecureTransport):
|
||||||
|
|||||||
Reference in New Issue
Block a user