Skip to content

Commit

Permalink
Fixed unexpected service creation and pylint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
raulikak committed Jun 4, 2024
1 parent 90dc51f commit ca1516d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
6 changes: 0 additions & 6 deletions tcsfw/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,6 @@ def __repr__(self) -> str:
return self.name


class Networks:
"""Network constants"""
# FIXME: Nuke!
Default = Network("Default") # Default network


class AddressEnvelope(AnyAddress):
"""Address envelope carrying content address"""
def __init__(self, address: AnyAddress, content: AnyAddress):
Expand Down
2 changes: 1 addition & 1 deletion tcsfw/builder_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import Any, Callable, Dict, List, Optional, Self, Tuple, Union

from tcsfw.address import (AddressAtNetwork, Addresses, AnyAddress, DNSName, EndpointAddress, EntityTag, HWAddress,
HWAddresses, IPAddress, IPAddresses, Network, Networks, Protocol)
HWAddresses, IPAddress, IPAddresses, Network, Protocol)
from tcsfw.address_resolver import AddressResolver
from tcsfw.basics import ConnectionType, ExternalActivity, HostType, Status
from tcsfw.batch_import import BatchImporter, LabelFilter
Expand Down
16 changes: 7 additions & 9 deletions tcsfw/matcher.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Match events into system model"""

from dataclasses import dataclass
import itertools
from typing import Self, Tuple, Dict, Optional, Set, List, Iterable

from tcsfw.address import AddressAtNetwork, AnyAddress, EndpointAddress, IPAddress, Addresses, DNSName, IPAddresses, Network, Networks
from tcsfw.address import AddressAtNetwork, AnyAddress, EndpointAddress, IPAddress, Addresses, DNSName
from tcsfw.basics import ExternalActivity, Status
from tcsfw.model import IoTSystem, Connection, Host, Addressable, Service, EvidenceNetworkSource, ModelListener
from tcsfw.property import Properties
Expand Down Expand Up @@ -262,10 +261,6 @@ def get_observed(self, flow: Flow) -> Optional[ConnectionMatch]:

def create_unknown_service(self, match: ConnectionMatch):
"""Create an unknown service due observing reply from it"""

# FIXME: Not updated with new address scheme
assert False, "Not implemented"

system = self.system.system
conn = match.connection
target_h = conn.target
Expand All @@ -279,9 +274,12 @@ def create_unknown_service(self, match: ConnectionMatch):
# host is free to provide unlisted services
n_service.status = Status.EXTERNAL
target_h.connections.append(conn)
for ep in self.endpoints[n_service_ep.get_host()]:
if ep.entity == target_h:
ep.add_service(n_service)
networks = target_h.get_networks_for(n_service_ep.get_host())
for nw in networks:
# for each network, the host is in
for ep in self.endpoints[AddressAtNetwork(n_service_ep.get_host(), nw)]:
if ep.entity == target_h:
ep.add_service(n_service)
conn.target = n_service
# create new connection for connections from same the source to the same target host, but different port
new_c = None
Expand Down
6 changes: 4 additions & 2 deletions tcsfw/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import List, Set, Optional, Tuple, TypeVar, Callable, Dict, Any, Self, Iterable, Iterator, Union
from urllib.parse import urlparse

from tcsfw.address import AnyAddress, Addresses, EndpointAddress, EntityTag, Network, Networks, Protocol, IPAddress, \
from tcsfw.address import AnyAddress, Addresses, EndpointAddress, EntityTag, Network, Protocol, IPAddress, \
HWAddress, DNSName
from tcsfw.basics import ConnectionType, ExternalActivity, HostType, Status
from tcsfw.entity import Entity
Expand Down Expand Up @@ -289,8 +289,10 @@ def create_service(self, address: EndpointAddress) -> 'Service':
nw = []
if address.get_ip_address():
nw = self.get_networks_for(address.get_ip_address())
if len(nw) == 1 and nw[0] == self.get_system().get_default_network():
nw = [] # default network not explicitlyt specified
# update name with network, if non-default
if nw and nw[0].name != "local": # (just little bit of inside knowledge here)
if len(nw) == 1:
s_name = f"{s_name}@{nw[0].name}"
s = Service(s_name, self)
if nw:
Expand Down

0 comments on commit ca1516d

Please sign in to comment.