Commit f0a65e81 authored by Juraj Sloboda's avatar Juraj Sloboda Committed by Matej Feder

Remove bp_node.py

parent 43bf5497
......@@ -12,7 +12,6 @@ from ..util.hexdump import hexdump
from . import convergence_layers
from .convergence_layers.api import ConnectFailedError
from .bp_node import get_bp_node_id
from .conn_manager import ConnectionManager, NoEndpointsForEIDError
from . import misc
......@@ -27,6 +26,7 @@ class NoContactError(Exception):
class BPAgent:
def __init__(self):
self._node_id = None
self._eid_registrations = []
self._routes = []
self._contacts = {}
......@@ -35,6 +35,7 @@ class BPAgent:
self._date_time_format = None
def init(self, node_config):
self._node_id = node_config['id']
self._date_time_format = node_config['date-time-format']
if 'routes' in node_config:
......@@ -43,6 +44,8 @@ class BPAgent:
for cla_name, cla_config in node_config['convergence-layer-adapters'].items():
cla_class = getattr(convergence_layers, cla_name)
# Save the Node ID inside the CLA config
cla_config['node-id'] = node_config['id']
cla = cla_class(cla_config)
self.register_cl_adapter(cla)
if 'neighbors' in cla_config:
......@@ -172,7 +175,7 @@ class BPAgent:
misc.make_contact(start_offset, end_offset, 500),
],
)
await self._create_and_send_bundle_msg(get_bp_node_id(), target_eid, inner_msg)
await self._create_and_send_bundle_msg(self._node_id, target_eid, inner_msg)
async def _recv_callback(self, conn):
logger.info('BP Agent is receiving bundle')
......
# API used by convergence layer adapters and bundle protocol layer
# Separate from bp_agent.py to avoid circular imports
import logging
logger = logging.getLogger(__name__)
_bp_node_id = None
def get_bp_node_id():
return _bp_node_id
def set_bp_node_id(eid):
global _bp_node_id
logger.info(f'Setting BP Node EID to "{eid}"')
_bp_node_id = eid
from abc import ABC, abstractmethod
from dataclasses import dataclass
from ..bp_node import get_bp_node_id
from ...util.exceptions import AlreadyRegisteredError
......@@ -29,7 +28,8 @@ class ConvergenceLayerAdapter(ABC):
else:
raise ValueError(f'{endpoint_class} already has attribute cla_class')
def __init__(self):
def __init__(self, endpoint):
self.node_id = endpoint['node-id']
self._endpoints = []
@abstractmethod
......@@ -52,12 +52,13 @@ class ConvergenceLayerAdapter(ABC):
class ConvergenceLayerConnection(ABC):
def __init__(self):
def __init__(self, cla_adapter):
self._cla_adapter = cla_adapter
self._their_eid = None
@property
def our_eid(self):
return get_bp_node_id()
return self._cla_adapter.node_id
@property
def their_eid(self):
......
......@@ -9,8 +9,8 @@ logger = logging.getLogger(__name__)
class StreamedConvergenceLayerConnection(ConvergenceLayerConnection):
def __init__(self, reader, writer):
super().__init__()
def __init__(self, cla_adapter, reader, writer):
super().__init__(cla_adapter)
self._their_eid = None
self._reader = WritebackReader(reader)
self._writer = writer
......
......@@ -23,7 +23,7 @@ class TCPCL(ConvergenceLayerAdapter):
endpoint_class = RemoteTCPEndpoint
def __init__(self, endpoint):
super().__init__()
super().__init__(endpoint)
self._host = endpoint['host']
self._port = endpoint['port']
self._upper_layer_handler = None
......@@ -35,7 +35,7 @@ class TCPCL(ConvergenceLayerAdapter):
reader, writer = await uio.open_connection(endpoint.host, endpoint.port)
except ConnectionRefusedError or TimeoutError:
raise ConnectFailedError
conn = TCPCLConnection(reader, writer)
conn = TCPCLConnection(self, reader, writer)
try:
await conn.start()
except Exception:
......@@ -47,7 +47,7 @@ class TCPCL(ConvergenceLayerAdapter):
async def _request_handler(self, reader, writer):
# TODO: Don't close the connection, but repeatedly call self._upper_layer_handler for every new bundle prefix
logger.info(f'TCPCL: Accepted connection')
conn = TCPCLConnection(reader, writer)
conn = TCPCLConnection(self, reader, writer)
try:
await conn.start()
await self._upper_layer_handler(conn)
......@@ -64,9 +64,6 @@ class TCPCL(ConvergenceLayerAdapter):
class TCPCLConnection(StreamedConvergenceLayerConnection):
def __init__(self, reader, writer):
super().__init__(reader, writer)
async def _recv_sdnv(self):
data = await self._recv(16)
try:
......
......@@ -5,7 +5,6 @@ import pkg_resources
import yaml
from .bundle_protocol import bp_agent
from .bundle_protocol.bp_node import set_bp_node_id
logger = logging.getLogger(__name__)
......@@ -39,8 +38,6 @@ async def start(config=None):
if node_id.endswith('default.dtn'):
logger.warning('Using default pyDTN config')
set_bp_node_id(node_id)
bp_agent.init(node_config)
# Start Bundle protocol agent
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment