koi-net 1.0.0b8__py3-none-any.whl → 1.0.0b9__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/processor/default_handlers.py +8 -15
- koi_net/processor/handler.py +9 -2
- koi_net/processor/interface.py +12 -4
- {koi_net-1.0.0b8.dist-info → koi_net-1.0.0b9.dist-info}/METADATA +151 -9
- {koi_net-1.0.0b8.dist-info → koi_net-1.0.0b9.dist-info}/RECORD +7 -7
- {koi_net-1.0.0b8.dist-info → koi_net-1.0.0b9.dist-info}/WHEEL +0 -0
- {koi_net-1.0.0b8.dist-info → koi_net-1.0.0b9.dist-info}/licenses/LICENSE +0 -0
|
@@ -26,20 +26,13 @@ def basic_rid_handler(processor: ProcessorInterface, kobj: KnowledgeObject):
|
|
|
26
26
|
return STOP_CHAIN
|
|
27
27
|
|
|
28
28
|
if kobj.event_type == EventType.FORGET:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
kobj.normalized_event_type = EventType.FORGET
|
|
32
|
-
return kobj
|
|
33
|
-
|
|
34
|
-
else:
|
|
35
|
-
# can't forget something I don't know about
|
|
36
|
-
return STOP_CHAIN
|
|
37
|
-
|
|
29
|
+
kobj.normalized_event_type = EventType.FORGET
|
|
30
|
+
return kobj
|
|
38
31
|
|
|
39
32
|
# Manifest handlers
|
|
40
33
|
|
|
41
34
|
@KnowledgeHandler.create(HandlerType.Manifest)
|
|
42
|
-
def
|
|
35
|
+
def basic_manifest_handler(processor: ProcessorInterface, kobj: KnowledgeObject):
|
|
43
36
|
"""Default manifest handler.
|
|
44
37
|
|
|
45
38
|
Blocks manifests with the same hash, or aren't newer than the cached version. Sets the normalized event type to `NEW` or `UPDATE` depending on whether the RID was previously known to this node.
|
|
@@ -66,7 +59,11 @@ def basic_state_handler(processor: ProcessorInterface, kobj: KnowledgeObject):
|
|
|
66
59
|
|
|
67
60
|
# Bundle handlers
|
|
68
61
|
|
|
69
|
-
@KnowledgeHandler.create(
|
|
62
|
+
@KnowledgeHandler.create(
|
|
63
|
+
handler_type=HandlerType.Bundle,
|
|
64
|
+
rid_types=[KoiNetEdge],
|
|
65
|
+
source=KnowledgeSource.External,
|
|
66
|
+
event_types=[EventType.NEW, EventType.UPDATE])
|
|
70
67
|
def edge_negotiation_handler(processor: ProcessorInterface, kobj: KnowledgeObject):
|
|
71
68
|
"""Handles basic edge negotiation process.
|
|
72
69
|
|
|
@@ -74,10 +71,6 @@ def edge_negotiation_handler(processor: ProcessorInterface, kobj: KnowledgeObjec
|
|
|
74
71
|
"""
|
|
75
72
|
|
|
76
73
|
edge_profile = EdgeProfile.model_validate(kobj.contents)
|
|
77
|
-
|
|
78
|
-
# only want to handle external knowledge events (not edges this node created)
|
|
79
|
-
if kobj.source != KnowledgeSource.External:
|
|
80
|
-
return
|
|
81
74
|
|
|
82
75
|
# indicates peer subscribing to me
|
|
83
76
|
if edge_profile.source == processor.identity.rid:
|
koi_net/processor/handler.py
CHANGED
|
@@ -3,6 +3,9 @@ from enum import StrEnum
|
|
|
3
3
|
from typing import Callable
|
|
4
4
|
from rid_lib import RIDType
|
|
5
5
|
|
|
6
|
+
from ..protocol.event import EventType
|
|
7
|
+
from .knowledge_object import KnowledgeSource, KnowledgeEventType
|
|
8
|
+
|
|
6
9
|
|
|
7
10
|
class StopChain:
|
|
8
11
|
"""Class for a sentinel value by knowledge handlers."""
|
|
@@ -34,19 +37,23 @@ class KnowledgeHandler:
|
|
|
34
37
|
func: Callable
|
|
35
38
|
handler_type: HandlerType
|
|
36
39
|
rid_types: list[RIDType] | None
|
|
40
|
+
source: KnowledgeSource | None = None
|
|
41
|
+
event_types: list[KnowledgeEventType] | None = None
|
|
37
42
|
|
|
38
43
|
@classmethod
|
|
39
44
|
def create(
|
|
40
45
|
cls,
|
|
41
46
|
handler_type: HandlerType,
|
|
42
|
-
rid_types: list[RIDType] | None = None
|
|
47
|
+
rid_types: list[RIDType] | None = None,
|
|
48
|
+
source: KnowledgeSource | None = None,
|
|
49
|
+
event_types: list[KnowledgeEventType] | None = None
|
|
43
50
|
):
|
|
44
51
|
"""Special decorator that returns a KnowledgeHandler instead of a function.
|
|
45
52
|
|
|
46
53
|
The function symbol will redefined as a `KnowledgeHandler`, which can be passed into the `ProcessorInterface` constructor. This is used to register default handlers.
|
|
47
54
|
"""
|
|
48
55
|
def decorator(func: Callable) -> KnowledgeHandler:
|
|
49
|
-
handler = cls(func, handler_type, rid_types)
|
|
56
|
+
handler = cls(func, handler_type, rid_types, source, event_types)
|
|
50
57
|
return handler
|
|
51
58
|
return decorator
|
|
52
59
|
|
koi_net/processor/interface.py
CHANGED
|
@@ -62,11 +62,13 @@ class ProcessorInterface:
|
|
|
62
62
|
def register_handler(
|
|
63
63
|
self,
|
|
64
64
|
handler_type: HandlerType,
|
|
65
|
-
rid_types: list[RIDType] | None = None
|
|
65
|
+
rid_types: list[RIDType] | None = None,
|
|
66
|
+
source: KnowledgeSource | None = None,
|
|
67
|
+
event_types: list[KnowledgeEventType] | None = None
|
|
66
68
|
):
|
|
67
69
|
"""Assigns decorated function as handler for this processor."""
|
|
68
70
|
def decorator(func: Callable) -> Callable:
|
|
69
|
-
handler = KnowledgeHandler(func, handler_type, rid_types)
|
|
71
|
+
handler = KnowledgeHandler(func, handler_type, rid_types, source, event_types)
|
|
70
72
|
self.add_handler(handler)
|
|
71
73
|
return func
|
|
72
74
|
return decorator
|
|
@@ -93,6 +95,12 @@ class ProcessorInterface:
|
|
|
93
95
|
if handler.rid_types and type(kobj.rid) not in handler.rid_types:
|
|
94
96
|
continue
|
|
95
97
|
|
|
98
|
+
if handler.source and handler.source != kobj.source:
|
|
99
|
+
continue
|
|
100
|
+
|
|
101
|
+
if handler.event_types and kobj.event_type not in handler.event_types:
|
|
102
|
+
continue
|
|
103
|
+
|
|
96
104
|
logger.info(f"Calling {handler_type} handler '{handler.func.__name__}'")
|
|
97
105
|
resp = handler.func(self, kobj.model_copy())
|
|
98
106
|
|
|
@@ -178,8 +186,8 @@ class ProcessorInterface:
|
|
|
178
186
|
kobj.manifest = bundle.manifest
|
|
179
187
|
kobj.contents = bundle.contents
|
|
180
188
|
|
|
181
|
-
|
|
182
|
-
|
|
189
|
+
kobj = self.call_handler_chain(HandlerType.Bundle, kobj)
|
|
190
|
+
if kobj is STOP_CHAIN: return
|
|
183
191
|
|
|
184
192
|
if kobj.normalized_event_type in (EventType.UPDATE, EventType.NEW):
|
|
185
193
|
logger.info(f"Writing {kobj!r} to cache")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: koi-net
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.0b9
|
|
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>
|
|
@@ -87,10 +87,10 @@ The request and payload JSON objects are composed of the fundamental "knowledge
|
|
|
87
87
|
}
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
This means that events are essentially just an RID, manifest, or bundle with an event type attached. Event types can be one of `FORGET`, `UPDATE`, or `NEW` forming the "FUN" acronym. While these types roughly correspond to delete, update, and create from CRUD operations, but they are not commands, they are signals. A node emits an event to indicate that its internal state has changed:
|
|
91
|
-
- `NEW` - indicates an previously unknown RID was cached
|
|
92
|
-
- `UPDATE` - indicates a previously known RID was cached
|
|
93
|
-
- `FORGET` - indicates a previously known RID was deleted
|
|
90
|
+
This means that events are essentially just an RID, manifest, or bundle with an event type attached. Event types can be one of `"FORGET"`, `"UPDATE"`, or `"NEW"` forming the "FUN" acronym. While these types roughly correspond to delete, update, and create from CRUD operations, but they are not commands, they are signals. A node emits an event to indicate that its internal state has changed:
|
|
91
|
+
- `"NEW"` - indicates an previously unknown RID was cached
|
|
92
|
+
- `"UPDATE"` - indicates a previously known RID was cached
|
|
93
|
+
- `"FORGET"` - indicates a previously known RID was deleted
|
|
94
94
|
|
|
95
95
|
Nodes may broadcast events to other nodes to indicate their internal state changed. Conversely, nodes may also listen to events from other nodes and as a result decide to change their internal state, take some other action, or do nothing.
|
|
96
96
|
|
|
@@ -149,12 +149,14 @@ node = NodeInterface(
|
|
|
149
149
|
)
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
+
When creating a node, you optionally enable `use_kobj_processor_thread` which will run the knowledge processing pipeline on a separate thread. This thread will automatically dequeue and process knowledge objects as they are added to the `kobj_queue`, which happenes when you call `node.process.handle(...)`. This is required to prevent race conditions in asynchronous applications, like web servers, therefore it is recommended to enable this feature for all full nodes.
|
|
153
|
+
|
|
152
154
|
## Knowledge Processing
|
|
153
155
|
|
|
154
156
|
Next we'll set up the knowledge processing flow for our node. This is where most of the node's logic and behavior will come into play. For partial nodes this will be an event loop, and for full nodes we will use webhooks. Make sure to call `node.start()` and `node.stop()` at the beginning and end of your node's life cycle.
|
|
155
157
|
|
|
156
158
|
### Partial Node
|
|
157
|
-
Make sure to set `source=KnowledgeSource.External
|
|
159
|
+
Make sure to set `source=KnowledgeSource.External` when calling `handle` on external knowledge, this indicates to the knowledge processing pipeline that the incoming knowledge was received from another node. Where the knowledge is sourced from will impact decisions in the node's knowledge handlers.
|
|
158
160
|
```python
|
|
159
161
|
import time
|
|
160
162
|
from koi_net.processor.knowledge_object import KnowledgeSource
|
|
@@ -252,6 +254,147 @@ python -m examples.basic_coordinator_node
|
|
|
252
254
|
python -m examples.basic_partial_node
|
|
253
255
|
```
|
|
254
256
|
|
|
257
|
+
# Advanced
|
|
258
|
+
|
|
259
|
+
## Knowledge Processing Pipeline
|
|
260
|
+
Beyond the `NodeInterface` setup and boiler plate for partial/full nodes, node behavior is mostly controlled through the use of knowledge handlers. Effectively creating your own handlers relies on a solid understanding of the knowledge processing pipeline, so we'll start with that. As a developer, you will interface with the pipeline through the `ProcessorInterface` accessed with `node.processor`. The pipeline handles knowledge objects, from the `KnowledgeObject` class, a container for all knowledge types in the RID / KOI-net ecosystem:
|
|
261
|
+
- RIDs
|
|
262
|
+
- Manifests
|
|
263
|
+
- Bundles
|
|
264
|
+
- Events
|
|
265
|
+
|
|
266
|
+
Here is the class definition for a knowledge object:
|
|
267
|
+
```python
|
|
268
|
+
type KnowledgeEventType = EventType | None
|
|
269
|
+
|
|
270
|
+
class KnowledgeSource(StrEnum):
|
|
271
|
+
Internal = "INTERNAL"
|
|
272
|
+
External = "EXTERNAL"
|
|
273
|
+
|
|
274
|
+
class KnowledgeObject(BaseModel):
|
|
275
|
+
rid: RID
|
|
276
|
+
manifest: Manifest | None = None
|
|
277
|
+
contents: dict | None = None
|
|
278
|
+
event_type: KnowledgeEventType = None
|
|
279
|
+
source: KnowledgeSource
|
|
280
|
+
normalized_event_type: KnowledgeEventType = None
|
|
281
|
+
network_targets: set[KoiNetNode] = set()
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
In addition to the fields required to represent the knowledge types (`rid`, `manifest`, `contents`, `event_type`), knowledge objects also include a `source` field, indicating whether the knowledge originated from within the node (`KnowledgeSource.Internal`) or from another node (`KnowledgeSource.External`).
|
|
285
|
+
|
|
286
|
+
The final two fields are not inputs, but are set by handlers as the knowledge object moves through the processing pipeline. The normalized event type indicates the event type normalized to the perspective of the node's cache, and the network targets indicate where the resulting event should be broadcasted to.
|
|
287
|
+
|
|
288
|
+
Knowledge objects enter the processing pipeline through the `node.processor.handle(...)` method. Using kwargs you can pass any of the knowledge types listed above, a knowledge source, and an optional `event_type` (for non-event knowledge types). The handle function will simply normalize the provided knowledge type into a knowledge object, and put it in the `kobj_queue`, an internal, thread-safe queue of knowledge objects. If you have enabled `use_kobj_processor_thread` then the queue will be automatically processed on the processor thread, otherwise you will need to regularly call `flush_kobj_queue` to process queued knowledge objects (as in the partial node example). Both methods will process knowledge objects sequentially, in the order that they were queued in (FIFO).
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
## Knowledge Handlers
|
|
292
|
+
|
|
293
|
+
Processing happens through five distinct phases, corresponding to the handler types: `RID`, `Manifest`, `Bundle`, `Network`, and `Final`. Each handler type can be understood by describing (1) what knowledge object fields are available to the handler, and (2) what action takes place after this phase, which the handler can influence. As knowledge objects pass through the pipeline, fields may be added or updated.
|
|
294
|
+
|
|
295
|
+
Handlers are registered in a single handler array within the processor. There is no limit to the number of handlers in use, and multiple handlers can be assigned to the same handler type. At each phase of knowledge processing, we will chain together all of the handlers of the corresponding type and run them in their array order. The order handlers are registered in matters!
|
|
296
|
+
|
|
297
|
+
Each handler will be passed a knowledge object. They can choose to return one of three types: `None`, `KnowledgeObject`, or `STOP_CHAIN`. Returning `None` will pass the unmodified knowledge object (the same one the handler received) to the next handler in the chain. If a handler modified their knowledge object, they should return it to pass the new version to the next handler. Finally, a handler can return `STOP_CHAIN` to immediately stop processing the knowledge object. No further handlers will be called and it will not enter the next phase of processing.
|
|
298
|
+
|
|
299
|
+
Summary of processing pipeline:
|
|
300
|
+
```
|
|
301
|
+
RID -> Manifest -> Bundle -> [cache action] -> Network -> [network action] -> Final
|
|
302
|
+
|
|
|
303
|
+
(skip if event type is "FORGET")
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### RID Handler
|
|
307
|
+
The knowledge object passed to handlers of this type are guaranteed to have an RID and knowledge source field. This handler type acts as a filter, if none of the handlers return `STOP_CHAIN` the pipeline will progress to the next phase. The pipeline diverges slightly after this handler chain, based on the event type of the knowledge object.
|
|
308
|
+
|
|
309
|
+
If the event type is `"NEW"`, `"UPDATE"`, or `None` and the manifest is not already in the knowledge object, the node will attempt to retrieve it from (1) the local cache if the source is internal, or (2) from another node if the source is external. If it fails to retrieves the manifest, the pipeline will end. Next, the manifest handler chain will be called.
|
|
310
|
+
|
|
311
|
+
If the event type is `"FORGET"`, and the bundle (manifest + contents) is not already in the knowledge object, the node will attempt to retrieve it from the local cache, regardless of the source. In this case the knowledge object represents what we will delete from the cache, not new incoming knowledge. If it fails to retrieve the bundle, the pipeline will end. Next, the bundle handler chain will be called.
|
|
312
|
+
|
|
313
|
+
### Manifest Handler
|
|
314
|
+
The knowledge object passed to handlers of this type are guaranteed to have an RID, manifest, and knowledge source field. This handler type acts as a filter, if none of the handlers return `STOP_CHAIN` the pipeline will progress to the next phase.
|
|
315
|
+
|
|
316
|
+
If the bundle (manifest + contents) is not already in the knowledge object, the node will attempt to retrieve it from (1) the local cache if the source is internal, or (2) from another node if the source is external. If it fails to retrieve the bundle, the pipeline will end. Next, the bundle handler chain will be called.
|
|
317
|
+
|
|
318
|
+
### Bundle Handler
|
|
319
|
+
The knowledge object passed to handlers of this type are guaranteed to have an RID, manifest, bundle (manifest + contents), and knowledge source field. This handler type acts as a decider. In this phase, the knowledge object's normalized event type must be set to `"NEW"` or `"UPDATE"` to write it to cache, or `"FORGET"` to delete it from the cache. If the normalized event type remains unset (`None`), or a handler returns `STOP_CHAIN`, then the pipeline will end without taking any cache action.
|
|
320
|
+
|
|
321
|
+
The cache action will take place after the handler chain ends, so if multiple handlers set a normalized event type, the final handler will take precedence.
|
|
322
|
+
|
|
323
|
+
### Network Handler
|
|
324
|
+
The knowledge object passed to handlers of this type are guaranteed to have an RID, manifest, bundle (manifest + contents), normalized event type, and knowledge source field. This handler type acts as a decider. In this phase, handlers decide which nodes to broadcast this knowledge object to by appending KOI-net node RIDs to the knowledge object's `network_targets` field. If a handler returns `STOP_CHAIN`, the pipeline will end without taking any network action.
|
|
325
|
+
|
|
326
|
+
The network action will take place after the handler chain ends. The node will attempt to broadcast a "normalized event", created from the knowledge object's RID, bundle, and normalized event type, to all of the node's in the network targets array.
|
|
327
|
+
|
|
328
|
+
### Final Handler
|
|
329
|
+
The knowledge object passed to handlers of this type are guaranteed to have an RID, manifest, bundle (manifest + contents), normalized event type, and knowledge source field.
|
|
330
|
+
|
|
331
|
+
This is the final handler chain that is called, it doesn't make any decisions or filter for succesive handler types. Handlers here can be useful if you want to take some action after the network broadcast has ended.
|
|
332
|
+
|
|
333
|
+
## Registering Handlers
|
|
334
|
+
Knowledge handlers are registered with a node's processor by decorating a handler function. There are two types of decorators, the first way converts the function into a handler object which can be manually added to a processor. This is how the default handlers are defined, and makes them more portable (could be imported from another package). The second automatically registers a handler with your node instance. This is not portable but more convenient. The input of the decorated function will be the processor instance, and a knowledge object.
|
|
335
|
+
|
|
336
|
+
```python
|
|
337
|
+
from .handler import KnowledgeHandler, HandlerType, STOP_CHAIN
|
|
338
|
+
|
|
339
|
+
@KnowledgeHandler.create(HandlerType.RID)
|
|
340
|
+
def example_handler(processor: ProcessorInterface, kobj: KnowledgeObject):
|
|
341
|
+
...
|
|
342
|
+
|
|
343
|
+
@node.processor.register_handler(HandlerType.RID)
|
|
344
|
+
def example_handler(processor: ProcessorInterface, kobj: KnowledgeObject):
|
|
345
|
+
...
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
While handler's only require specifying the handler type, you can also specify the RID types, knowledge source, or event types you want to handle. If a knowledge object doesn't match all of the specified parameters, it won't be called. By default, handlers will match all RID types, all event types, and both internal and external sourced knowledge.
|
|
349
|
+
|
|
350
|
+
```python
|
|
351
|
+
@KnowledgeHandler.create(
|
|
352
|
+
handler_type=HandlerType.Bundle,
|
|
353
|
+
rid_types=[KoiNetEdge],
|
|
354
|
+
source=KnowledgeSource.External,
|
|
355
|
+
event_types=[EventType.NEW, EventType.UPDATE])
|
|
356
|
+
def edge_negotiation_handler(processor: ProcessorInterface, kobj: KnowledgeObject):
|
|
357
|
+
...
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
The processor instance passed to your function should be used to take any necessary node actions (cache, network, etc.). It is also sometimes useful to add new knowledge objects to the queue while processing a different knowledge object. You can simply call `processor.handle(...)` in the same way as you would outside of a handler. It will put at the end of the queue and processed when it is dequeued like any other knowledge object.
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
## Default Behavior
|
|
364
|
+
|
|
365
|
+
The default configuration provides four default handlers which will take precedence over any handlers you add yourself. To override this behavior, you can set the `handlers` field in the `NodeInterface`:
|
|
366
|
+
|
|
367
|
+
```python
|
|
368
|
+
from koi_net import NodeInterface
|
|
369
|
+
from koi_net.protocol.node import NodeProfile, NodeProvides, NodeType
|
|
370
|
+
from koi_net.processor.default_handlers import (
|
|
371
|
+
basic_rid_handler,
|
|
372
|
+
basic_manifest_handler,
|
|
373
|
+
edge_negotiation_handler,
|
|
374
|
+
basic_network_output_filter
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
node = NodeInterface(
|
|
378
|
+
name="mypartialnode",
|
|
379
|
+
profile=NodeProfile(
|
|
380
|
+
node_type=NodeType.PARTIAL,
|
|
381
|
+
provides=NodeProvides(
|
|
382
|
+
event=[]
|
|
383
|
+
)
|
|
384
|
+
),
|
|
385
|
+
handlers=[
|
|
386
|
+
basic_rid_handler,
|
|
387
|
+
basic_manifest_handler,
|
|
388
|
+
edge_negotiation_handler,
|
|
389
|
+
basic_network_output_filter
|
|
390
|
+
|
|
391
|
+
# include all or none of the default handlers
|
|
392
|
+
]
|
|
393
|
+
)
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
Take a look at `src/koi_net/processor/default_handlers.py` to see some more in depth examples and better understand the default node behavior.
|
|
397
|
+
|
|
255
398
|
# Implementation Reference
|
|
256
399
|
This section provides high level explanations of the Python implementation. More detailed explanations of methods can be found in the docstrings within the codebase itself.
|
|
257
400
|
|
|
@@ -464,14 +607,13 @@ class ProcessorInterface:
|
|
|
464
607
|
event: Event | None = None,
|
|
465
608
|
kobj: KnowledgeObject | None = None,
|
|
466
609
|
event_type: KnowledgeEventType = None,
|
|
467
|
-
source: KnowledgeSource = KnowledgeSource.Internal
|
|
468
|
-
flush: bool = False
|
|
610
|
+
source: KnowledgeSource = KnowledgeSource.Internal
|
|
469
611
|
): ...
|
|
470
612
|
```
|
|
471
613
|
|
|
472
614
|
The `register_handler` method is a decorator which can wrap a function to create a new `KnowledgeHandler` and add it to the processing pipeline in a single step. The `add_handler` method adds an existing `KnowledgeHandler` to the processining pipeline.
|
|
473
615
|
|
|
474
|
-
The most commonly used functions in this class are `handle` and `flush_kobj_queue`. The `handle` method can be called on RIDs, manifests, bundles, and events to convert them to normalized to `KnowledgeObject` instances which are then added to the processing queue.
|
|
616
|
+
The most commonly used functions in this class are `handle` and `flush_kobj_queue`. The `handle` method can be called on RIDs, manifests, bundles, and events to convert them to normalized to `KnowledgeObject` instances which are then added to the processing queue. If you have enabled `use_kobj_processor_thread` then the queue will be automatically processed, otherwise you will need to regularly call `flush_kobj_queue` to process queued knolwedge objects. When calling the `handle` method, knowledge objects are marked as internally source by default. If you are handling RIDs, manifests, bundles, or events sourced from other nodes, `source` should be set to `KnowledgeSource.External`.
|
|
475
617
|
|
|
476
618
|
Here is an example of how an event polling loop would be implemented using the knowledge processing pipeline:
|
|
477
619
|
```python
|
|
@@ -7,9 +7,9 @@ koi_net/network/interface.py,sha256=4JTeg8Eah0z5YKhcVKJbCVZw_Ghl_6xfG8aa1I5PCWI,
|
|
|
7
7
|
koi_net/network/request_handler.py,sha256=fhuCDsxI8fZ4p5TntcTZR4mnLrLQ61zDy7Oca3ooFCE,4402
|
|
8
8
|
koi_net/network/response_handler.py,sha256=HaP8Fl0bp_lfMmevhdVY8s9o0Uf8CR1ZaW5g3jsX8gw,1888
|
|
9
9
|
koi_net/processor/__init__.py,sha256=x4fAY0hvQEDcpfdTB3POIzxBQjYAtn0qQazPo1Xm0m4,41
|
|
10
|
-
koi_net/processor/default_handlers.py,sha256=
|
|
11
|
-
koi_net/processor/handler.py,sha256=
|
|
12
|
-
koi_net/processor/interface.py,sha256=
|
|
10
|
+
koi_net/processor/default_handlers.py,sha256=cdGDFb4z1vnDmAXQO5XeDjhbUHbB8TndC-E6AFJzp2M,6930
|
|
11
|
+
koi_net/processor/handler.py,sha256=a2wxG3kgux-07YP13HSj_PH5VH_PjbnTS4uZEHjxMw0,2582
|
|
12
|
+
koi_net/processor/interface.py,sha256=5zYxaD_ATjjp1xFunRomCrrzjyspi8zZzeY2Rca7bVU,12522
|
|
13
13
|
koi_net/processor/knowledge_object.py,sha256=cGv33fwNZQMylkhlTaQTbk96FVIVbdOUaBsG06u0m4k,4187
|
|
14
14
|
koi_net/protocol/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
15
|
koi_net/protocol/api_models.py,sha256=RDwVHAahiWzwzUnlj5MIm9et5WVpQOaG-Uscv1B9coU,1116
|
|
@@ -18,7 +18,7 @@ koi_net/protocol/edge.py,sha256=G3D9Ie0vbTSMJdoTw9g_oBmFCqzJ1gO7U1PVrw7p3j8,447
|
|
|
18
18
|
koi_net/protocol/event.py,sha256=dzJmcHbimo7p5NwH2drccF0vMcAj9oQRj3iZ9Bjf7kg,1275
|
|
19
19
|
koi_net/protocol/helpers.py,sha256=9E9PaoIuSNrTBATGCLJ_kSBMZ2z-KIMnLJzGOTqQDC0,719
|
|
20
20
|
koi_net/protocol/node.py,sha256=Ntrx01dbm39ViKGtr4gLmztcMwKpTIweS6rRL-zoU_Y,391
|
|
21
|
-
koi_net-1.0.
|
|
22
|
-
koi_net-1.0.
|
|
23
|
-
koi_net-1.0.
|
|
24
|
-
koi_net-1.0.
|
|
21
|
+
koi_net-1.0.0b9.dist-info/METADATA,sha256=GZbTzNd_k5uVlvaik7_YXdYd17Ya6XtVTf6NXrxbRes,32539
|
|
22
|
+
koi_net-1.0.0b9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
23
|
+
koi_net-1.0.0b9.dist-info/licenses/LICENSE,sha256=XBcvl8yjCAezfuqN1jadQykrX7H2g4nr2WRDmHLW6ik,1090
|
|
24
|
+
koi_net-1.0.0b9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|