koi-net 1.0.0b14__py3-none-any.whl → 1.0.0b16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of koi-net might be problematic. Click here for more details.
- koi_net/config.py +9 -3
- koi_net/identity.py +3 -3
- koi_net/network/interface.py +1 -1
- koi_net/processor/default_handlers.py +53 -0
- koi_net/processor/interface.py +3 -3
- {koi_net-1.0.0b14.dist-info → koi_net-1.0.0b16.dist-info}/METADATA +1 -1
- {koi_net-1.0.0b14.dist-info → koi_net-1.0.0b16.dist-info}/RECORD +9 -9
- {koi_net-1.0.0b14.dist-info → koi_net-1.0.0b16.dist-info}/WHEEL +0 -0
- {koi_net-1.0.0b14.dist-info → koi_net-1.0.0b16.dist-info}/licenses/LICENSE +0 -0
koi_net/config.py
CHANGED
|
@@ -40,7 +40,7 @@ class EnvConfig(BaseModel):
|
|
|
40
40
|
return env_val
|
|
41
41
|
return value
|
|
42
42
|
|
|
43
|
-
class
|
|
43
|
+
class NodeConfig(BaseModel):
|
|
44
44
|
server: ServerConfig | None = Field(default_factory=ServerConfig)
|
|
45
45
|
koi_net: KoiNetConfig
|
|
46
46
|
_file_path: str = PrivateAttr(default="config.yaml")
|
|
@@ -49,7 +49,7 @@ class Config(BaseModel):
|
|
|
49
49
|
@classmethod
|
|
50
50
|
def load_from_yaml(
|
|
51
51
|
cls,
|
|
52
|
-
file_path: str
|
|
52
|
+
file_path: str = "config.yaml",
|
|
53
53
|
generate_missing: bool = True
|
|
54
54
|
):
|
|
55
55
|
yaml = YAML()
|
|
@@ -62,8 +62,14 @@ class Config(BaseModel):
|
|
|
62
62
|
config._file_content = file_content
|
|
63
63
|
|
|
64
64
|
except FileNotFoundError:
|
|
65
|
+
# empty_fields = {}
|
|
66
|
+
# for name, field in cls.model_fields.items():
|
|
67
|
+
|
|
68
|
+
# if field.default is None or field.default_factory is None:
|
|
69
|
+
# print(empty_fields)
|
|
65
70
|
config = cls()
|
|
66
71
|
|
|
72
|
+
|
|
67
73
|
config._file_path = file_path
|
|
68
74
|
|
|
69
75
|
if generate_missing:
|
|
@@ -92,4 +98,4 @@ class Config(BaseModel):
|
|
|
92
98
|
f.write(self._file_content)
|
|
93
99
|
raise e
|
|
94
100
|
|
|
95
|
-
ConfigType = TypeVar("ConfigType", bound=
|
|
101
|
+
ConfigType = TypeVar("ConfigType", bound=NodeConfig)
|
koi_net/identity.py
CHANGED
|
@@ -3,7 +3,7 @@ from rid_lib.ext.bundle import Bundle
|
|
|
3
3
|
from rid_lib.ext.cache import Cache
|
|
4
4
|
from rid_lib.types.koi_net_node import KoiNetNode
|
|
5
5
|
|
|
6
|
-
from .config import
|
|
6
|
+
from .config import NodeConfig
|
|
7
7
|
from .protocol.node import NodeProfile
|
|
8
8
|
|
|
9
9
|
logger = logging.getLogger(__name__)
|
|
@@ -12,12 +12,12 @@ logger = logging.getLogger(__name__)
|
|
|
12
12
|
class NodeIdentity:
|
|
13
13
|
"""Represents a node's identity (RID, profile, bundle)."""
|
|
14
14
|
|
|
15
|
-
config:
|
|
15
|
+
config: NodeConfig
|
|
16
16
|
cache: Cache
|
|
17
17
|
|
|
18
18
|
def __init__(
|
|
19
19
|
self,
|
|
20
|
-
config:
|
|
20
|
+
config: NodeConfig,
|
|
21
21
|
cache: Cache
|
|
22
22
|
):
|
|
23
23
|
"""Initializes node identity from a name and profile.
|
koi_net/network/interface.py
CHANGED
|
@@ -15,7 +15,7 @@ from ..protocol.node import NodeType
|
|
|
15
15
|
from ..protocol.edge import EdgeType
|
|
16
16
|
from ..protocol.event import Event
|
|
17
17
|
from ..identity import NodeIdentity
|
|
18
|
-
from ..config import
|
|
18
|
+
from ..config import ConfigType
|
|
19
19
|
|
|
20
20
|
logger = logging.getLogger(__name__)
|
|
21
21
|
|
|
@@ -9,6 +9,8 @@ from .handler import KnowledgeHandler, HandlerType, STOP_CHAIN
|
|
|
9
9
|
from .knowledge_object import KnowledgeObject, KnowledgeSource
|
|
10
10
|
from ..protocol.event import Event, EventType
|
|
11
11
|
from ..protocol.edge import EdgeProfile, EdgeStatus, EdgeType
|
|
12
|
+
from ..protocol.node import NodeProfile
|
|
13
|
+
from ..protocol.helpers import generate_edge_bundle
|
|
12
14
|
|
|
13
15
|
logger = logging.getLogger(__name__)
|
|
14
16
|
|
|
@@ -124,6 +126,57 @@ def edge_negotiation_handler(processor: ProcessorInterface, kobj: KnowledgeObjec
|
|
|
124
126
|
|
|
125
127
|
# Network handlers
|
|
126
128
|
|
|
129
|
+
@KnowledgeHandler.create(HandlerType.Network, rid_types=[KoiNetNode])
|
|
130
|
+
def coordinator_contact(processor: ProcessorInterface, kobj: KnowledgeObject):
|
|
131
|
+
node_profile = kobj.bundle.validate_contents(NodeProfile)
|
|
132
|
+
|
|
133
|
+
# looking for event provider of nodes
|
|
134
|
+
if KoiNetNode not in node_profile.provides.event:
|
|
135
|
+
return
|
|
136
|
+
|
|
137
|
+
# already have an edge established
|
|
138
|
+
if processor.network.graph.get_edge_profile(
|
|
139
|
+
source=kobj.rid,
|
|
140
|
+
target=processor.identity.rid,
|
|
141
|
+
) is not None:
|
|
142
|
+
return
|
|
143
|
+
|
|
144
|
+
logger.info("Identified a coordinator!")
|
|
145
|
+
logger.info("Proposing new edge")
|
|
146
|
+
|
|
147
|
+
if processor.identity.profile.node_type == NodeType.FULL:
|
|
148
|
+
edge_type = EdgeType.WEBHOOK
|
|
149
|
+
else:
|
|
150
|
+
edge_type = EdgeType.POLL
|
|
151
|
+
|
|
152
|
+
# queued for processing
|
|
153
|
+
processor.handle(bundle=generate_edge_bundle(
|
|
154
|
+
source=kobj.rid,
|
|
155
|
+
target=processor.identity.rid,
|
|
156
|
+
edge_type=edge_type,
|
|
157
|
+
rid_types=[KoiNetNode]
|
|
158
|
+
))
|
|
159
|
+
|
|
160
|
+
logger.info("Catching up on network state")
|
|
161
|
+
|
|
162
|
+
payload = processor.network.request_handler.fetch_rids(
|
|
163
|
+
node=kobj.rid,
|
|
164
|
+
rid_types=[KoiNetNode]
|
|
165
|
+
)
|
|
166
|
+
for rid in payload.rids:
|
|
167
|
+
if rid == processor.identity.rid:
|
|
168
|
+
logger.info("Skipping myself")
|
|
169
|
+
continue
|
|
170
|
+
if processor.cache.exists(rid):
|
|
171
|
+
logger.info(f"Skipping known RID '{rid}'")
|
|
172
|
+
continue
|
|
173
|
+
|
|
174
|
+
# marked as external since we are handling RIDs from another node
|
|
175
|
+
# will fetch remotely instead of checking local cache
|
|
176
|
+
processor.handle(rid=rid, source=KnowledgeSource.External)
|
|
177
|
+
logger.info("Done")
|
|
178
|
+
|
|
179
|
+
|
|
127
180
|
@KnowledgeHandler.create(HandlerType.Network)
|
|
128
181
|
def basic_network_output_filter(processor: ProcessorInterface, kobj: KnowledgeObject):
|
|
129
182
|
"""Default network handler.
|
koi_net/processor/interface.py
CHANGED
|
@@ -9,7 +9,7 @@ from rid_lib.types.koi_net_node import KoiNetNode
|
|
|
9
9
|
from ..identity import NodeIdentity
|
|
10
10
|
from ..network import NetworkInterface
|
|
11
11
|
from ..protocol.event import Event, EventType
|
|
12
|
-
from ..config import
|
|
12
|
+
from ..config import NodeConfig
|
|
13
13
|
from .handler import (
|
|
14
14
|
KnowledgeHandler,
|
|
15
15
|
HandlerType,
|
|
@@ -28,7 +28,7 @@ logger = logging.getLogger(__name__)
|
|
|
28
28
|
class ProcessorInterface():
|
|
29
29
|
"""Provides access to this node's knowledge processing pipeline."""
|
|
30
30
|
|
|
31
|
-
config:
|
|
31
|
+
config: NodeConfig
|
|
32
32
|
cache: Cache
|
|
33
33
|
network: NetworkInterface
|
|
34
34
|
identity: NodeIdentity
|
|
@@ -39,7 +39,7 @@ class ProcessorInterface():
|
|
|
39
39
|
|
|
40
40
|
def __init__(
|
|
41
41
|
self,
|
|
42
|
-
config:
|
|
42
|
+
config: NodeConfig,
|
|
43
43
|
cache: Cache,
|
|
44
44
|
network: NetworkInterface,
|
|
45
45
|
identity: NodeIdentity,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
koi_net/__init__.py,sha256=b0Ze0pZmJAuygpWUFHM6Kvqo3DkU_uzmkptv1EpAArw,31
|
|
2
|
-
koi_net/config.py,sha256=
|
|
2
|
+
koi_net/config.py,sha256=35RNSOcWxnJzasPAkYabFWcKyDR-2kM1NTrq_fYOkm0,3153
|
|
3
3
|
koi_net/core.py,sha256=IO8kqiNMYVeuNzilq7eHBA7IulsxRjrCbWnIAx6_abA,4406
|
|
4
|
-
koi_net/identity.py,sha256=
|
|
4
|
+
koi_net/identity.py,sha256=muc5vuQ8zUOebhwAB3-ql6W2pgQETiYXXQAFBv8bLyg,1288
|
|
5
5
|
koi_net/network/__init__.py,sha256=r_RN-q_mDYC-2RAkN-lJoMUX76TXyfEUc_MVKW87z0g,39
|
|
6
6
|
koi_net/network/graph.py,sha256=dsfPuHUTkCzlj0QeL0e7dgp7-FR5_AGP7eE8EpBPhC0,4710
|
|
7
|
-
koi_net/network/interface.py,sha256=
|
|
7
|
+
koi_net/network/interface.py,sha256=CKZACkUxG6Y4GV8XR16lhFLzRpXOw59hx7sFewZ_35w,10466
|
|
8
8
|
koi_net/network/request_handler.py,sha256=66gjX2x4UnBWZYwKLjp_3WkhL-ekhR3VAyfGviHTcUs,4790
|
|
9
9
|
koi_net/network/response_handler.py,sha256=CAwici2Etj9ESndERXdtYkMlc4gWHz_xc7jHgY2Qjcg,1830
|
|
10
10
|
koi_net/processor/__init__.py,sha256=x4fAY0hvQEDcpfdTB3POIzxBQjYAtn0qQazPo1Xm0m4,41
|
|
11
|
-
koi_net/processor/default_handlers.py,sha256=
|
|
11
|
+
koi_net/processor/default_handlers.py,sha256=f8Yl21lLGMa_oW51bf8sBuunfP9_rmiSu32T-rZ4kUY,8542
|
|
12
12
|
koi_net/processor/handler.py,sha256=7X6M6PP8m6-xdtsP1y4QO83g_MN5VSszNNikprITK80,2523
|
|
13
|
-
koi_net/processor/interface.py,sha256=
|
|
13
|
+
koi_net/processor/interface.py,sha256=3ofjBFz3FVjESABXJ1aC_4ESTuLFMHyl5d8uWz5QsFA,13012
|
|
14
14
|
koi_net/processor/knowledge_object.py,sha256=RCgzkILsWm1Jw_NkSu4jTRYA9Ugga6mJ4jqKWwketQs,4090
|
|
15
15
|
koi_net/protocol/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
16
|
koi_net/protocol/api_models.py,sha256=DYDKCRD2Uja633bBAyTsaxyb1oF9pX9yQ9NpNAbkczo,1070
|
|
@@ -19,7 +19,7 @@ koi_net/protocol/edge.py,sha256=CcmvIY4P1HEBdKNJ4wFRDmwYMRMss24Besmbi7ZRFxQ,427
|
|
|
19
19
|
koi_net/protocol/event.py,sha256=HxzLN-iCXPyr2YzrswMIkgZYeUdFbBpa5v98dAB06lQ,1328
|
|
20
20
|
koi_net/protocol/helpers.py,sha256=8ZkQrjb_G0QEaMIKe9wkFOBonl1bkmemx_pwKMwIiLg,695
|
|
21
21
|
koi_net/protocol/node.py,sha256=2HhCh3LdBLlY2Z_kXNmKHzpVLKbP_ODob3HjHayFQtM,375
|
|
22
|
-
koi_net-1.0.
|
|
23
|
-
koi_net-1.0.
|
|
24
|
-
koi_net-1.0.
|
|
25
|
-
koi_net-1.0.
|
|
22
|
+
koi_net-1.0.0b16.dist-info/METADATA,sha256=YQ_kvSI7441neMoeU6uy5SMpt1Lo2ZwKx_KsIAbu0WE,34203
|
|
23
|
+
koi_net-1.0.0b16.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
24
|
+
koi_net-1.0.0b16.dist-info/licenses/LICENSE,sha256=03mgCL5qth2aD9C3F3qNVs4sFJSpK9kjtYCyOwdSp7s,1069
|
|
25
|
+
koi_net-1.0.0b16.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|