You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
-276Lines changed: 0 additions & 276 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -401,282 +401,6 @@ node = NodeInterface(
401
401
402
402
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.
403
403
404
-
# Implementation Reference
405
-
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.
406
-
407
-
## Node Interface
408
-
The node class mostly acts as a container for other classes with more specialized behavior, with special functions that should be called to start up and shut down a node. We'll take a look at each of these components in turn, but here is the class stub:
409
-
```python
410
-
classNodeInterface:
411
-
config: ConfigType
412
-
cache: Cache
413
-
identity: NodeIdentity
414
-
network: NetworkInterface
415
-
processor: ProcessorInterface
416
-
417
-
use_kobj_processor_thread: bool
418
-
419
-
def__init__(
420
-
self,
421
-
config: ConfigType,
422
-
use_kobj_processor_thread: bool=False,
423
-
424
-
handlers: list[KnowledgeHandler] |None=None,
425
-
426
-
cache: Cache |None=None,
427
-
network: NetworkInterface |None=None,
428
-
processor: ProcessorInterface |None=None
429
-
): ...
430
-
431
-
defstart(self): ...
432
-
defstop(self): ...
433
-
```
434
-
As you can see, only a node config is required, all other fields are optional.
435
-
436
-
## Node Config
437
-
438
-
The node config class is a mix of configuration groups providing basic shared behavior across nodes through a standard interface. The class is implemented as Pydantic model, but provides functions to load from and save to a YAML file, the expected format within a node repo.
Nodes are expected to create new node config classes inheriting from `NodeConfig`. You may want to set a default KoiNetConfig (see examples) to allow for a default config to be generated if not provided by the user. Environment variables can be handled by inheriting from the `EnvConfig` class and adding new string fields. The value of this field should be equivalent to the environment variable name, for example:
This special config class will automatically load in the variables from the current environment, or local `.env` file. Beyond these base config classes, you are free to add your own config groups. See `config.py` in the [koi-net-slack-sensor-node](https://github.com/BlockScience/koi-net-slack-sensor-node/blob/main/slack_sensor_node/config.py) repo for a more complete example.
486
-
487
-
## Node Identity
488
-
The `NodeIdentity` class provides easy access to a node's own RID, profile, and bundle. It provides access to the following properties after initialization, accessed with `node.identity`.
489
-
```python
490
-
classNodeIdentity:
491
-
rid: KoiNetNode # an RID type
492
-
profile: NodeProfile
493
-
bundle: Bundle
494
-
```
495
-
This it what is initialized from the required `name` and `profile` fields in the `NodeConfig` class. Node RIDs take the form of `orn:koi-net.node:<name>+<uuid>`, and are generated on first use to the identity JSON file along with a the node profile.
496
-
497
-
## Network Interface
498
-
The `NetworkInterface` class provides access to high level network actions, and contains several other network related classes. It is accessed with `node.network`.
Most of the provided functions are abstractions for KOI-net protocol actions. It also contains three lower level classes: `NetworkGraph`, `RequestHandler`, and `ResponseHandler`.
526
-
527
-
### Network Graph
528
-
The `NetworkGraph` class provides access to a graph view of the node's KOI network: all of the KOI-net node and edge objects it knows about (stored in local cache). This view allows us to query nodes that we have edges with to make networking decisions.
Handles raw API requests to other nodes through the KOI-net protocol. Accepts a node RID or direct URL as the target. Each method requires either a valid request model, or `kwargs` which will be converted to the correct model in `koi_net.protocol.api_models`.
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.
670
-
671
-
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`.
672
-
673
-
Here is an example of how an event polling loop would be implemented using the knowledge processing pipeline:
0 commit comments