koi-net 1.0.0b10__py3-none-any.whl → 1.0.0b12__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/core.py +125 -125
- koi_net/identity.py +69 -69
- koi_net/network/graph.py +127 -127
- koi_net/network/interface.py +273 -273
- koi_net/network/request_handler.py +148 -148
- koi_net/network/response_handler.py +58 -58
- koi_net/processor/default_handlers.py +162 -162
- koi_net/processor/handler.py +59 -59
- koi_net/processor/interface.py +298 -295
- koi_net/processor/knowledge_object.py +122 -122
- koi_net/protocol/api_models.py +46 -46
- koi_net/protocol/consts.py +6 -6
- koi_net/protocol/edge.py +20 -20
- koi_net/protocol/event.py +50 -50
- koi_net/protocol/helpers.py +24 -24
- koi_net/protocol/node.py +16 -16
- {koi_net-1.0.0b10.dist-info → koi_net-1.0.0b12.dist-info}/METADATA +4 -2
- koi_net-1.0.0b12.dist-info/RECORD +24 -0
- {koi_net-1.0.0b10.dist-info → koi_net-1.0.0b12.dist-info}/licenses/LICENSE +21 -21
- koi_net-1.0.0b10.dist-info/RECORD +0 -24
- {koi_net-1.0.0b10.dist-info → koi_net-1.0.0b12.dist-info}/WHEEL +0 -0
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
from enum import StrEnum
|
|
2
|
-
from pydantic import BaseModel
|
|
3
|
-
from rid_lib import RID
|
|
4
|
-
from rid_lib.ext import Manifest
|
|
5
|
-
from rid_lib.ext.bundle import Bundle
|
|
6
|
-
from rid_lib.types.koi_net_node import KoiNetNode
|
|
7
|
-
from ..protocol.event import Event, EventType
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type KnowledgeEventType = EventType | None
|
|
11
|
-
|
|
12
|
-
class KnowledgeSource(StrEnum):
|
|
13
|
-
Internal = "INTERNAL"
|
|
14
|
-
External = "EXTERNAL"
|
|
15
|
-
|
|
16
|
-
class KnowledgeObject(BaseModel):
|
|
17
|
-
"""A normalized knowledge representation for internal processing.
|
|
18
|
-
|
|
19
|
-
Capable of representing an RID, manifest, bundle, or event. Contains three additional fields use for decision making in the knowledge processing pipeline.
|
|
20
|
-
|
|
21
|
-
The source indicates whether this object was generated by this node, or sourced from another node in the network.
|
|
22
|
-
|
|
23
|
-
The normalized event type indicates how the knowledge object is viewed from the perspective of this node, and what cache actions will take place. `NEW`, `UPDATE` -> cache write, `FORGET` -> cache delete, `None` -> no cache action.
|
|
24
|
-
|
|
25
|
-
The network targets indicate other nodes in the network this knowledge object will be sent to. The event sent to them will be constructed from this knowledge object's RID, manifest, contents, and normalized event type.
|
|
26
|
-
|
|
27
|
-
Constructors are provided to create a knowledge object from an RID, manifest, bundle, or event.
|
|
28
|
-
"""
|
|
29
|
-
rid: RID
|
|
30
|
-
manifest: Manifest | None = None
|
|
31
|
-
contents: dict | None = None
|
|
32
|
-
event_type: KnowledgeEventType = None
|
|
33
|
-
normalized_event_type: KnowledgeEventType = None
|
|
34
|
-
source: KnowledgeSource
|
|
35
|
-
network_targets: set[KoiNetNode] = set()
|
|
36
|
-
|
|
37
|
-
def __repr__(self):
|
|
38
|
-
return f"<KObj '{self.rid}' event type: '{self.event_type}' -> '{self.normalized_event_type}', source: '{self.source}'>"
|
|
39
|
-
|
|
40
|
-
@classmethod
|
|
41
|
-
def from_rid(
|
|
42
|
-
cls,
|
|
43
|
-
rid: RID,
|
|
44
|
-
event_type: KnowledgeEventType = None,
|
|
45
|
-
source: KnowledgeSource = KnowledgeSource.Internal
|
|
46
|
-
) -> "KnowledgeObject":
|
|
47
|
-
return cls(
|
|
48
|
-
rid=rid,
|
|
49
|
-
event_type=event_type,
|
|
50
|
-
source=source
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
@classmethod
|
|
54
|
-
def from_manifest(
|
|
55
|
-
cls,
|
|
56
|
-
manifest: Manifest,
|
|
57
|
-
event_type: KnowledgeEventType = None,
|
|
58
|
-
source: KnowledgeSource = KnowledgeSource.Internal
|
|
59
|
-
) -> "KnowledgeObject":
|
|
60
|
-
return cls(
|
|
61
|
-
rid=manifest.rid,
|
|
62
|
-
manifest=manifest,
|
|
63
|
-
event_type=event_type,
|
|
64
|
-
source=source
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
@classmethod
|
|
68
|
-
def from_bundle(
|
|
69
|
-
cls,
|
|
70
|
-
bundle: Bundle,
|
|
71
|
-
event_type: KnowledgeEventType = None,
|
|
72
|
-
source: KnowledgeSource = KnowledgeSource.Internal
|
|
73
|
-
) -> "KnowledgeObject":
|
|
74
|
-
return cls(
|
|
75
|
-
rid=bundle.rid,
|
|
76
|
-
manifest=bundle.manifest,
|
|
77
|
-
contents=bundle.contents,
|
|
78
|
-
event_type=event_type,
|
|
79
|
-
source=source
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
@classmethod
|
|
83
|
-
def from_event(
|
|
84
|
-
cls,
|
|
85
|
-
event: Event,
|
|
86
|
-
source: KnowledgeSource = KnowledgeSource.Internal
|
|
87
|
-
) -> "KnowledgeObject":
|
|
88
|
-
return cls(
|
|
89
|
-
rid=event.rid,
|
|
90
|
-
manifest=event.manifest,
|
|
91
|
-
contents=event.contents,
|
|
92
|
-
event_type=event.event_type,
|
|
93
|
-
source=source
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
@property
|
|
97
|
-
def bundle(self):
|
|
98
|
-
if self.manifest is None or self.contents is None:
|
|
99
|
-
return
|
|
100
|
-
|
|
101
|
-
return Bundle(
|
|
102
|
-
manifest=self.manifest,
|
|
103
|
-
contents=self.contents
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
@property
|
|
107
|
-
def normalized_event(self):
|
|
108
|
-
if self.normalized_event_type is None:
|
|
109
|
-
raise ValueError("Internal event's normalized event type is None, cannot convert to Event")
|
|
110
|
-
|
|
111
|
-
elif self.normalized_event_type == EventType.FORGET:
|
|
112
|
-
return Event(
|
|
113
|
-
rid=self.rid,
|
|
114
|
-
event_type=EventType.FORGET
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
else:
|
|
118
|
-
return Event(
|
|
119
|
-
rid=self.rid,
|
|
120
|
-
event_type=self.normalized_event_type,
|
|
121
|
-
manifest=self.manifest,
|
|
122
|
-
contents=self.contents
|
|
1
|
+
from enum import StrEnum
|
|
2
|
+
from pydantic import BaseModel
|
|
3
|
+
from rid_lib import RID
|
|
4
|
+
from rid_lib.ext import Manifest
|
|
5
|
+
from rid_lib.ext.bundle import Bundle
|
|
6
|
+
from rid_lib.types.koi_net_node import KoiNetNode
|
|
7
|
+
from ..protocol.event import Event, EventType
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
type KnowledgeEventType = EventType | None
|
|
11
|
+
|
|
12
|
+
class KnowledgeSource(StrEnum):
|
|
13
|
+
Internal = "INTERNAL"
|
|
14
|
+
External = "EXTERNAL"
|
|
15
|
+
|
|
16
|
+
class KnowledgeObject(BaseModel):
|
|
17
|
+
"""A normalized knowledge representation for internal processing.
|
|
18
|
+
|
|
19
|
+
Capable of representing an RID, manifest, bundle, or event. Contains three additional fields use for decision making in the knowledge processing pipeline.
|
|
20
|
+
|
|
21
|
+
The source indicates whether this object was generated by this node, or sourced from another node in the network.
|
|
22
|
+
|
|
23
|
+
The normalized event type indicates how the knowledge object is viewed from the perspective of this node, and what cache actions will take place. `NEW`, `UPDATE` -> cache write, `FORGET` -> cache delete, `None` -> no cache action.
|
|
24
|
+
|
|
25
|
+
The network targets indicate other nodes in the network this knowledge object will be sent to. The event sent to them will be constructed from this knowledge object's RID, manifest, contents, and normalized event type.
|
|
26
|
+
|
|
27
|
+
Constructors are provided to create a knowledge object from an RID, manifest, bundle, or event.
|
|
28
|
+
"""
|
|
29
|
+
rid: RID
|
|
30
|
+
manifest: Manifest | None = None
|
|
31
|
+
contents: dict | None = None
|
|
32
|
+
event_type: KnowledgeEventType = None
|
|
33
|
+
normalized_event_type: KnowledgeEventType = None
|
|
34
|
+
source: KnowledgeSource
|
|
35
|
+
network_targets: set[KoiNetNode] = set()
|
|
36
|
+
|
|
37
|
+
def __repr__(self):
|
|
38
|
+
return f"<KObj '{self.rid}' event type: '{self.event_type}' -> '{self.normalized_event_type}', source: '{self.source}'>"
|
|
39
|
+
|
|
40
|
+
@classmethod
|
|
41
|
+
def from_rid(
|
|
42
|
+
cls,
|
|
43
|
+
rid: RID,
|
|
44
|
+
event_type: KnowledgeEventType = None,
|
|
45
|
+
source: KnowledgeSource = KnowledgeSource.Internal
|
|
46
|
+
) -> "KnowledgeObject":
|
|
47
|
+
return cls(
|
|
48
|
+
rid=rid,
|
|
49
|
+
event_type=event_type,
|
|
50
|
+
source=source
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def from_manifest(
|
|
55
|
+
cls,
|
|
56
|
+
manifest: Manifest,
|
|
57
|
+
event_type: KnowledgeEventType = None,
|
|
58
|
+
source: KnowledgeSource = KnowledgeSource.Internal
|
|
59
|
+
) -> "KnowledgeObject":
|
|
60
|
+
return cls(
|
|
61
|
+
rid=manifest.rid,
|
|
62
|
+
manifest=manifest,
|
|
63
|
+
event_type=event_type,
|
|
64
|
+
source=source
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
@classmethod
|
|
68
|
+
def from_bundle(
|
|
69
|
+
cls,
|
|
70
|
+
bundle: Bundle,
|
|
71
|
+
event_type: KnowledgeEventType = None,
|
|
72
|
+
source: KnowledgeSource = KnowledgeSource.Internal
|
|
73
|
+
) -> "KnowledgeObject":
|
|
74
|
+
return cls(
|
|
75
|
+
rid=bundle.rid,
|
|
76
|
+
manifest=bundle.manifest,
|
|
77
|
+
contents=bundle.contents,
|
|
78
|
+
event_type=event_type,
|
|
79
|
+
source=source
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def from_event(
|
|
84
|
+
cls,
|
|
85
|
+
event: Event,
|
|
86
|
+
source: KnowledgeSource = KnowledgeSource.Internal
|
|
87
|
+
) -> "KnowledgeObject":
|
|
88
|
+
return cls(
|
|
89
|
+
rid=event.rid,
|
|
90
|
+
manifest=event.manifest,
|
|
91
|
+
contents=event.contents,
|
|
92
|
+
event_type=event.event_type,
|
|
93
|
+
source=source
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
@property
|
|
97
|
+
def bundle(self):
|
|
98
|
+
if self.manifest is None or self.contents is None:
|
|
99
|
+
return
|
|
100
|
+
|
|
101
|
+
return Bundle(
|
|
102
|
+
manifest=self.manifest,
|
|
103
|
+
contents=self.contents
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def normalized_event(self):
|
|
108
|
+
if self.normalized_event_type is None:
|
|
109
|
+
raise ValueError("Internal event's normalized event type is None, cannot convert to Event")
|
|
110
|
+
|
|
111
|
+
elif self.normalized_event_type == EventType.FORGET:
|
|
112
|
+
return Event(
|
|
113
|
+
rid=self.rid,
|
|
114
|
+
event_type=EventType.FORGET
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
else:
|
|
118
|
+
return Event(
|
|
119
|
+
rid=self.rid,
|
|
120
|
+
event_type=self.normalized_event_type,
|
|
121
|
+
manifest=self.manifest,
|
|
122
|
+
contents=self.contents
|
|
123
123
|
)
|
koi_net/protocol/api_models.py
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
"""Pydantic models for request and response/payload objects in the KOI-net API."""
|
|
2
|
-
|
|
3
|
-
from pydantic import BaseModel
|
|
4
|
-
from rid_lib import RID, RIDType
|
|
5
|
-
from rid_lib.ext import Bundle, Manifest
|
|
6
|
-
from .event import Event
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
# REQUEST MODELS
|
|
10
|
-
|
|
11
|
-
class PollEvents(BaseModel):
|
|
12
|
-
rid: RID
|
|
13
|
-
limit: int = 0
|
|
14
|
-
|
|
15
|
-
class FetchRids(BaseModel):
|
|
16
|
-
rid_types: list[RIDType] = []
|
|
17
|
-
|
|
18
|
-
class FetchManifests(BaseModel):
|
|
19
|
-
rid_types: list[RIDType] = []
|
|
20
|
-
rids: list[RID] = []
|
|
21
|
-
|
|
22
|
-
class FetchBundles(BaseModel):
|
|
23
|
-
rids: list[RID]
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
# RESPONSE/PAYLOAD MODELS
|
|
27
|
-
|
|
28
|
-
class RidsPayload(BaseModel):
|
|
29
|
-
rids: list[RID]
|
|
30
|
-
|
|
31
|
-
class ManifestsPayload(BaseModel):
|
|
32
|
-
manifests: list[Manifest]
|
|
33
|
-
not_found: list[RID] = []
|
|
34
|
-
|
|
35
|
-
class BundlesPayload(BaseModel):
|
|
36
|
-
bundles: list[Bundle]
|
|
37
|
-
not_found: list[RID] = []
|
|
38
|
-
deferred: list[RID] = []
|
|
39
|
-
|
|
40
|
-
class EventsPayload(BaseModel):
|
|
41
|
-
events: list[Event]
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
# TYPES
|
|
45
|
-
|
|
46
|
-
type RequestModels = EventsPayload | PollEvents | FetchRids | FetchManifests | FetchBundles
|
|
1
|
+
"""Pydantic models for request and response/payload objects in the KOI-net API."""
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
from rid_lib import RID, RIDType
|
|
5
|
+
from rid_lib.ext import Bundle, Manifest
|
|
6
|
+
from .event import Event
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# REQUEST MODELS
|
|
10
|
+
|
|
11
|
+
class PollEvents(BaseModel):
|
|
12
|
+
rid: RID
|
|
13
|
+
limit: int = 0
|
|
14
|
+
|
|
15
|
+
class FetchRids(BaseModel):
|
|
16
|
+
rid_types: list[RIDType] = []
|
|
17
|
+
|
|
18
|
+
class FetchManifests(BaseModel):
|
|
19
|
+
rid_types: list[RIDType] = []
|
|
20
|
+
rids: list[RID] = []
|
|
21
|
+
|
|
22
|
+
class FetchBundles(BaseModel):
|
|
23
|
+
rids: list[RID]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# RESPONSE/PAYLOAD MODELS
|
|
27
|
+
|
|
28
|
+
class RidsPayload(BaseModel):
|
|
29
|
+
rids: list[RID]
|
|
30
|
+
|
|
31
|
+
class ManifestsPayload(BaseModel):
|
|
32
|
+
manifests: list[Manifest]
|
|
33
|
+
not_found: list[RID] = []
|
|
34
|
+
|
|
35
|
+
class BundlesPayload(BaseModel):
|
|
36
|
+
bundles: list[Bundle]
|
|
37
|
+
not_found: list[RID] = []
|
|
38
|
+
deferred: list[RID] = []
|
|
39
|
+
|
|
40
|
+
class EventsPayload(BaseModel):
|
|
41
|
+
events: list[Event]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# TYPES
|
|
45
|
+
|
|
46
|
+
type RequestModels = EventsPayload | PollEvents | FetchRids | FetchManifests | FetchBundles
|
|
47
47
|
type ResponseModels = RidsPayload | ManifestsPayload | BundlesPayload | EventsPayload
|
koi_net/protocol/consts.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"""API paths for KOI-net protocol."""
|
|
2
|
-
|
|
3
|
-
BROADCAST_EVENTS_PATH = "/events/broadcast"
|
|
4
|
-
POLL_EVENTS_PATH = "/events/poll"
|
|
5
|
-
FETCH_RIDS_PATH = "/rids/fetch"
|
|
6
|
-
FETCH_MANIFESTS_PATH = "/manifests/fetch"
|
|
1
|
+
"""API paths for KOI-net protocol."""
|
|
2
|
+
|
|
3
|
+
BROADCAST_EVENTS_PATH = "/events/broadcast"
|
|
4
|
+
POLL_EVENTS_PATH = "/events/poll"
|
|
5
|
+
FETCH_RIDS_PATH = "/rids/fetch"
|
|
6
|
+
FETCH_MANIFESTS_PATH = "/manifests/fetch"
|
|
7
7
|
FETCH_BUNDLES_PATH = "/bundles/fetch"
|
koi_net/protocol/edge.py
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
from enum import StrEnum
|
|
2
|
-
from pydantic import BaseModel
|
|
3
|
-
from rid_lib import RIDType
|
|
4
|
-
from rid_lib.types import KoiNetNode
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class EdgeStatus(StrEnum):
|
|
8
|
-
PROPOSED = "PROPOSED"
|
|
9
|
-
APPROVED = "APPROVED"
|
|
10
|
-
|
|
11
|
-
class EdgeType(StrEnum):
|
|
12
|
-
WEBHOOK = "WEBHOOK"
|
|
13
|
-
POLL = "POLL"
|
|
14
|
-
|
|
15
|
-
class EdgeProfile(BaseModel):
|
|
16
|
-
source: KoiNetNode
|
|
17
|
-
target: KoiNetNode
|
|
18
|
-
edge_type: EdgeType
|
|
19
|
-
status: EdgeStatus
|
|
20
|
-
rid_types: list[RIDType]
|
|
1
|
+
from enum import StrEnum
|
|
2
|
+
from pydantic import BaseModel
|
|
3
|
+
from rid_lib import RIDType
|
|
4
|
+
from rid_lib.types import KoiNetNode
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class EdgeStatus(StrEnum):
|
|
8
|
+
PROPOSED = "PROPOSED"
|
|
9
|
+
APPROVED = "APPROVED"
|
|
10
|
+
|
|
11
|
+
class EdgeType(StrEnum):
|
|
12
|
+
WEBHOOK = "WEBHOOK"
|
|
13
|
+
POLL = "POLL"
|
|
14
|
+
|
|
15
|
+
class EdgeProfile(BaseModel):
|
|
16
|
+
source: KoiNetNode
|
|
17
|
+
target: KoiNetNode
|
|
18
|
+
edge_type: EdgeType
|
|
19
|
+
status: EdgeStatus
|
|
20
|
+
rid_types: list[RIDType]
|
koi_net/protocol/event.py
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
from enum import StrEnum
|
|
2
|
-
from pydantic import BaseModel
|
|
3
|
-
from rid_lib import RID
|
|
4
|
-
from rid_lib.ext import Manifest, Bundle
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class EventType(StrEnum):
|
|
8
|
-
NEW = "NEW"
|
|
9
|
-
UPDATE = "UPDATE"
|
|
10
|
-
FORGET = "FORGET"
|
|
11
|
-
|
|
12
|
-
class Event(BaseModel):
|
|
13
|
-
rid: RID
|
|
14
|
-
event_type: EventType
|
|
15
|
-
manifest: Manifest | None = None
|
|
16
|
-
contents: dict | None = None
|
|
17
|
-
|
|
18
|
-
def __repr__(self):
|
|
19
|
-
return f"<Event '{self.rid}' event type: '{self.event_type}'>"
|
|
20
|
-
|
|
21
|
-
@classmethod
|
|
22
|
-
def from_bundle(cls, event_type: EventType, bundle: Bundle):
|
|
23
|
-
return cls(
|
|
24
|
-
rid=bundle.manifest.rid,
|
|
25
|
-
event_type=event_type,
|
|
26
|
-
manifest=bundle.manifest,
|
|
27
|
-
contents=bundle.contents
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
@classmethod
|
|
31
|
-
def from_manifest(cls, event_type: EventType, manifest: Manifest):
|
|
32
|
-
return cls(
|
|
33
|
-
rid=manifest.rid,
|
|
34
|
-
event_type=event_type,
|
|
35
|
-
manifest=manifest
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
@classmethod
|
|
39
|
-
def from_rid(cls, event_type: EventType, rid: RID):
|
|
40
|
-
return cls(
|
|
41
|
-
rid=rid,
|
|
42
|
-
event_type=event_type
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
@property
|
|
46
|
-
def bundle(self):
|
|
47
|
-
if self.manifest is not None and self.contents is not None:
|
|
48
|
-
return Bundle(
|
|
49
|
-
manifest=self.manifest,
|
|
50
|
-
contents=self.contents
|
|
1
|
+
from enum import StrEnum
|
|
2
|
+
from pydantic import BaseModel
|
|
3
|
+
from rid_lib import RID
|
|
4
|
+
from rid_lib.ext import Manifest, Bundle
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class EventType(StrEnum):
|
|
8
|
+
NEW = "NEW"
|
|
9
|
+
UPDATE = "UPDATE"
|
|
10
|
+
FORGET = "FORGET"
|
|
11
|
+
|
|
12
|
+
class Event(BaseModel):
|
|
13
|
+
rid: RID
|
|
14
|
+
event_type: EventType
|
|
15
|
+
manifest: Manifest | None = None
|
|
16
|
+
contents: dict | None = None
|
|
17
|
+
|
|
18
|
+
def __repr__(self):
|
|
19
|
+
return f"<Event '{self.rid}' event type: '{self.event_type}'>"
|
|
20
|
+
|
|
21
|
+
@classmethod
|
|
22
|
+
def from_bundle(cls, event_type: EventType, bundle: Bundle):
|
|
23
|
+
return cls(
|
|
24
|
+
rid=bundle.manifest.rid,
|
|
25
|
+
event_type=event_type,
|
|
26
|
+
manifest=bundle.manifest,
|
|
27
|
+
contents=bundle.contents
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
@classmethod
|
|
31
|
+
def from_manifest(cls, event_type: EventType, manifest: Manifest):
|
|
32
|
+
return cls(
|
|
33
|
+
rid=manifest.rid,
|
|
34
|
+
event_type=event_type,
|
|
35
|
+
manifest=manifest
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
@classmethod
|
|
39
|
+
def from_rid(cls, event_type: EventType, rid: RID):
|
|
40
|
+
return cls(
|
|
41
|
+
rid=rid,
|
|
42
|
+
event_type=event_type
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def bundle(self):
|
|
47
|
+
if self.manifest is not None and self.contents is not None:
|
|
48
|
+
return Bundle(
|
|
49
|
+
manifest=self.manifest,
|
|
50
|
+
contents=self.contents
|
|
51
51
|
)
|
koi_net/protocol/helpers.py
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
from rid_lib.core import RIDType
|
|
2
|
-
from rid_lib.ext.bundle import Bundle
|
|
3
|
-
from rid_lib.types import KoiNetEdge
|
|
4
|
-
from rid_lib.types.koi_net_node import KoiNetNode
|
|
5
|
-
from .edge import EdgeProfile, EdgeStatus, EdgeType
|
|
6
|
-
|
|
7
|
-
def generate_edge_bundle(
|
|
8
|
-
source: KoiNetNode,
|
|
9
|
-
target: KoiNetNode,
|
|
10
|
-
rid_types: list[RIDType],
|
|
11
|
-
edge_type: EdgeType
|
|
12
|
-
) -> Bundle:
|
|
13
|
-
edge_rid = KoiNetEdge.generate(source, target)
|
|
14
|
-
edge_profile = EdgeProfile(
|
|
15
|
-
source=source,
|
|
16
|
-
target=target,
|
|
17
|
-
rid_types=rid_types,
|
|
18
|
-
edge_type=edge_type,
|
|
19
|
-
status=EdgeStatus.PROPOSED
|
|
20
|
-
)
|
|
21
|
-
edge_bundle = Bundle.generate(
|
|
22
|
-
edge_rid,
|
|
23
|
-
edge_profile.model_dump()
|
|
24
|
-
)
|
|
1
|
+
from rid_lib.core import RIDType
|
|
2
|
+
from rid_lib.ext.bundle import Bundle
|
|
3
|
+
from rid_lib.types import KoiNetEdge
|
|
4
|
+
from rid_lib.types.koi_net_node import KoiNetNode
|
|
5
|
+
from .edge import EdgeProfile, EdgeStatus, EdgeType
|
|
6
|
+
|
|
7
|
+
def generate_edge_bundle(
|
|
8
|
+
source: KoiNetNode,
|
|
9
|
+
target: KoiNetNode,
|
|
10
|
+
rid_types: list[RIDType],
|
|
11
|
+
edge_type: EdgeType
|
|
12
|
+
) -> Bundle:
|
|
13
|
+
edge_rid = KoiNetEdge.generate(source, target)
|
|
14
|
+
edge_profile = EdgeProfile(
|
|
15
|
+
source=source,
|
|
16
|
+
target=target,
|
|
17
|
+
rid_types=rid_types,
|
|
18
|
+
edge_type=edge_type,
|
|
19
|
+
status=EdgeStatus.PROPOSED
|
|
20
|
+
)
|
|
21
|
+
edge_bundle = Bundle.generate(
|
|
22
|
+
edge_rid,
|
|
23
|
+
edge_profile.model_dump()
|
|
24
|
+
)
|
|
25
25
|
return edge_bundle
|
koi_net/protocol/node.py
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
from enum import StrEnum
|
|
2
|
-
from pydantic import BaseModel
|
|
3
|
-
from rid_lib import RIDType
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class NodeType(StrEnum):
|
|
7
|
-
FULL = "FULL"
|
|
8
|
-
PARTIAL = "PARTIAL"
|
|
9
|
-
|
|
10
|
-
class NodeProvides(BaseModel):
|
|
11
|
-
event: list[RIDType] = []
|
|
12
|
-
state: list[RIDType] = []
|
|
13
|
-
|
|
14
|
-
class NodeProfile(BaseModel):
|
|
15
|
-
base_url: str | None = None
|
|
16
|
-
node_type: NodeType
|
|
1
|
+
from enum import StrEnum
|
|
2
|
+
from pydantic import BaseModel
|
|
3
|
+
from rid_lib import RIDType
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class NodeType(StrEnum):
|
|
7
|
+
FULL = "FULL"
|
|
8
|
+
PARTIAL = "PARTIAL"
|
|
9
|
+
|
|
10
|
+
class NodeProvides(BaseModel):
|
|
11
|
+
event: list[RIDType] = []
|
|
12
|
+
state: list[RIDType] = []
|
|
13
|
+
|
|
14
|
+
class NodeProfile(BaseModel):
|
|
15
|
+
base_url: str | None = None
|
|
16
|
+
node_type: NodeType
|
|
17
17
|
provides: NodeProvides = NodeProvides()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: koi-net
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.0b12
|
|
4
4
|
Summary: Implementation of KOI-net protocol in Python
|
|
5
5
|
Project-URL: Homepage, https://github.com/BlockScience/koi-net/
|
|
6
6
|
Author-email: Luke Miller <luke@block.science>
|
|
@@ -118,7 +118,9 @@ The request and payload JSON objects are composed of the fundamental "knowledge
|
|
|
118
118
|
}
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
An event is a signalling construct that conveys information about RID objects between networked nodes. Events are composed of an RID, manifest, or bundle with an event type attached. Event types can be one of `"FORGET"`, `"UPDATE"`, or `"NEW"` forming the "FUN" acronym.
|
|
122
|
+
|
|
123
|
+
As opposed to CRUD (create, read, update, delete), events are a series of messages, not operations. Each node has its own autonomy in deciding how to react based on the message it receives. For example, a processor node may receive a `"NEW"` event for an RID object its not interested in, and ignore it. Or it may decide that an `"UPDATE"` event should trigger fetching a bundle from another node. A node emits an event to indicate that its internal state has changed:
|
|
122
124
|
- `"NEW"` - indicates an previously unknown RID was cached
|
|
123
125
|
- `"UPDATE"` - indicates a previously known RID was cached
|
|
124
126
|
- `"FORGET"` - indicates a previously known RID was deleted
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
koi_net/__init__.py,sha256=b0Ze0pZmJAuygpWUFHM6Kvqo3DkU_uzmkptv1EpAArw,31
|
|
2
|
+
koi_net/core.py,sha256=7tSGGdV_EYUKNF5q7q5gV0KCelkuDLQapQhcB4GiZAQ,4562
|
|
3
|
+
koi_net/identity.py,sha256=xSWmAgG2RJbixijdELPI--LSgHxrNteEcTN1M0Ekib4,2317
|
|
4
|
+
koi_net/network/__init__.py,sha256=r_RN-q_mDYC-2RAkN-lJoMUX76TXyfEUc_MVKW87z0g,39
|
|
5
|
+
koi_net/network/graph.py,sha256=dsfPuHUTkCzlj0QeL0e7dgp7-FR5_AGP7eE8EpBPhC0,4710
|
|
6
|
+
koi_net/network/interface.py,sha256=-_pkWEcUIdWyvwJxaoPpiE8yVlg5w7c417U7cBTawuw,10387
|
|
7
|
+
koi_net/network/request_handler.py,sha256=66gjX2x4UnBWZYwKLjp_3WkhL-ekhR3VAyfGviHTcUs,4790
|
|
8
|
+
koi_net/network/response_handler.py,sha256=CAwici2Etj9ESndERXdtYkMlc4gWHz_xc7jHgY2Qjcg,1830
|
|
9
|
+
koi_net/processor/__init__.py,sha256=x4fAY0hvQEDcpfdTB3POIzxBQjYAtn0qQazPo1Xm0m4,41
|
|
10
|
+
koi_net/processor/default_handlers.py,sha256=vfQNvucQR5zANyYhdLnc3kOXGFrgNtq5swd-vH7n0Uo,6810
|
|
11
|
+
koi_net/processor/handler.py,sha256=7X6M6PP8m6-xdtsP1y4QO83g_MN5VSszNNikprITK80,2523
|
|
12
|
+
koi_net/processor/interface.py,sha256=Qvm0TaYB8kLraiLArupHx0KivI4yB83gOsiGirUkvcw,12890
|
|
13
|
+
koi_net/processor/knowledge_object.py,sha256=RCgzkILsWm1Jw_NkSu4jTRYA9Ugga6mJ4jqKWwketQs,4090
|
|
14
|
+
koi_net/protocol/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
+
koi_net/protocol/api_models.py,sha256=DYDKCRD2Uja633bBAyTsaxyb1oF9pX9yQ9NpNAbkczo,1070
|
|
16
|
+
koi_net/protocol/consts.py,sha256=bisbVEojPIHlLhkLafBzfIhH25TjNfvTORF1g6YXzIM,243
|
|
17
|
+
koi_net/protocol/edge.py,sha256=CcmvIY4P1HEBdKNJ4wFRDmwYMRMss24Besmbi7ZRFxQ,427
|
|
18
|
+
koi_net/protocol/event.py,sha256=HxzLN-iCXPyr2YzrswMIkgZYeUdFbBpa5v98dAB06lQ,1328
|
|
19
|
+
koi_net/protocol/helpers.py,sha256=8ZkQrjb_G0QEaMIKe9wkFOBonl1bkmemx_pwKMwIiLg,695
|
|
20
|
+
koi_net/protocol/node.py,sha256=2HhCh3LdBLlY2Z_kXNmKHzpVLKbP_ODob3HjHayFQtM,375
|
|
21
|
+
koi_net-1.0.0b12.dist-info/METADATA,sha256=0ic3QADnehpTrxpXo4VqruuhEw74N7tDaKYyvFsBEvY,34131
|
|
22
|
+
koi_net-1.0.0b12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
23
|
+
koi_net-1.0.0b12.dist-info/licenses/LICENSE,sha256=03mgCL5qth2aD9C3F3qNVs4sFJSpK9kjtYCyOwdSp7s,1069
|
|
24
|
+
koi_net-1.0.0b12.dist-info/RECORD,,
|