mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-10 15:10:54 +00:00
Migrate to new project structure.
This commit is contained in:
0
libp2p/network/connection/__init__.py
Normal file
0
libp2p/network/connection/__init__.py
Normal file
25
libp2p/network/connection/raw_connection.py
Normal file
25
libp2p/network/connection/raw_connection.py
Normal file
@ -0,0 +1,25 @@
|
||||
from .raw_connection_interface import IRawConnection
|
||||
|
||||
|
||||
class RawConnection(IRawConnection):
|
||||
|
||||
def __init__(self, ip, port, reader, writer, initiator):
|
||||
# pylint: disable=too-many-arguments
|
||||
self.conn_ip = ip
|
||||
self.conn_port = port
|
||||
self.reader = reader
|
||||
self.writer = writer
|
||||
self._next_id = 0 if initiator else 1
|
||||
self.initiator = initiator
|
||||
|
||||
def close(self):
|
||||
self.writer.close()
|
||||
|
||||
def next_stream_id(self):
|
||||
"""
|
||||
Get next available stream id
|
||||
:return: next available stream id for the connection
|
||||
"""
|
||||
next_id = self._next_id
|
||||
self._next_id += 2
|
||||
return next_id
|
||||
9
libp2p/network/connection/raw_connection_interface.py
Normal file
9
libp2p/network/connection/raw_connection_interface.py
Normal file
@ -0,0 +1,9 @@
|
||||
from abc import ABC
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
|
||||
|
||||
class IRawConnection(ABC):
|
||||
"""
|
||||
A Raw Connection provides a Reader and a Writer
|
||||
"""
|
||||
Reference in New Issue
Block a user