koi-net 1.1.0b8__py3-none-any.whl → 1.2.0b2__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.

Files changed (48) hide show
  1. koi_net/__init__.py +2 -1
  2. koi_net/assembler.py +82 -0
  3. koi_net/cli/__init__.py +1 -0
  4. koi_net/cli/commands.py +99 -0
  5. koi_net/cli/models.py +41 -0
  6. koi_net/config.py +34 -0
  7. koi_net/context.py +11 -28
  8. koi_net/core.py +63 -179
  9. koi_net/default_actions.py +10 -1
  10. koi_net/effector.py +61 -34
  11. koi_net/handshaker.py +39 -0
  12. koi_net/identity.py +2 -3
  13. koi_net/interfaces/entrypoint.py +5 -0
  14. koi_net/interfaces/worker.py +17 -0
  15. koi_net/lifecycle.py +85 -48
  16. koi_net/logger.py +176 -0
  17. koi_net/network/error_handler.py +18 -16
  18. koi_net/network/event_queue.py +17 -185
  19. koi_net/network/graph.py +15 -10
  20. koi_net/network/poll_event_buffer.py +26 -0
  21. koi_net/network/request_handler.py +54 -47
  22. koi_net/network/resolver.py +18 -21
  23. koi_net/network/response_handler.py +79 -15
  24. koi_net/poller.py +18 -9
  25. koi_net/processor/event_worker.py +117 -0
  26. koi_net/processor/handler.py +4 -2
  27. koi_net/processor/{default_handlers.py → handlers.py} +109 -59
  28. koi_net/processor/knowledge_object.py +19 -7
  29. koi_net/processor/kobj_queue.py +51 -0
  30. koi_net/processor/kobj_worker.py +44 -0
  31. koi_net/processor/{knowledge_pipeline.py → pipeline.py} +31 -53
  32. koi_net/protocol/api_models.py +7 -3
  33. koi_net/protocol/envelope.py +5 -6
  34. koi_net/protocol/model_map.py +61 -0
  35. koi_net/protocol/node.py +3 -3
  36. koi_net/protocol/secure.py +8 -8
  37. koi_net/secure.py +33 -13
  38. koi_net/sentry.py +13 -0
  39. koi_net/server.py +44 -78
  40. koi_net/utils.py +18 -0
  41. {koi_net-1.1.0b8.dist-info → koi_net-1.2.0b2.dist-info}/METADATA +8 -3
  42. koi_net-1.2.0b2.dist-info/RECORD +52 -0
  43. koi_net-1.2.0b2.dist-info/entry_points.txt +2 -0
  44. koi_net/actor.py +0 -60
  45. koi_net/processor/interface.py +0 -101
  46. koi_net-1.1.0b8.dist-info/RECORD +0 -38
  47. {koi_net-1.1.0b8.dist-info → koi_net-1.2.0b2.dist-info}/WHEEL +0 -0
  48. {koi_net-1.1.0b8.dist-info → koi_net-1.2.0b2.dist-info}/licenses/LICENSE +0 -0
koi_net/server.py CHANGED
@@ -1,60 +1,42 @@
1
- import logging
1
+ import structlog
2
2
  import uvicorn
3
3
  from contextlib import asynccontextmanager
4
4
  from fastapi import FastAPI, APIRouter
5
5
  from fastapi.responses import JSONResponse
6
- from .network.event_queue import NetworkEventQueue
6
+
7
+ from koi_net.interfaces.entrypoint import EntryPoint
8
+
7
9
  from .network.response_handler import ResponseHandler
8
- from .processor.interface import ProcessorInterface
9
- from .protocol.api_models import (
10
- PollEvents,
11
- FetchRids,
12
- FetchManifests,
13
- FetchBundles,
14
- EventsPayload,
15
- RidsPayload,
16
- ManifestsPayload,
17
- BundlesPayload,
18
- ErrorResponse
19
- )
10
+ from .protocol.model_map import API_MODEL_MAP
11
+ from .protocol.api_models import ErrorResponse
20
12
  from .protocol.errors import ProtocolError
21
- from .protocol.envelope import SignedEnvelope
22
- from .protocol.consts import (
23
- BROADCAST_EVENTS_PATH,
24
- POLL_EVENTS_PATH,
25
- FETCH_RIDS_PATH,
26
- FETCH_MANIFESTS_PATH,
27
- FETCH_BUNDLES_PATH
28
- )
29
- from .secure import Secure
30
13
  from .lifecycle import NodeLifecycle
31
14
  from .config import NodeConfig
32
15
 
33
- logger = logging.getLogger(__name__)
16
+ log = structlog.stdlib.get_logger()
34
17
 
35
18
 
36
- class NodeServer:
19
+ class NodeServer(EntryPoint):
20
+ """Manages FastAPI server and event handling for full nodes."""
21
+ config: NodeConfig
37
22
  lifecycle: NodeLifecycle
23
+ response_handler: ResponseHandler
24
+ app: FastAPI
25
+ router: APIRouter
38
26
 
39
27
  def __init__(
40
28
  self,
41
29
  config: NodeConfig,
42
30
  lifecycle: NodeLifecycle,
43
- secure: Secure,
44
- processor: ProcessorInterface,
45
- event_queue: NetworkEventQueue,
46
- response_handler: ResponseHandler
31
+ response_handler: ResponseHandler,
47
32
  ):
48
33
  self.config = config
49
34
  self.lifecycle = lifecycle
50
- self.secure = secure
51
- self.processor = processor
52
- self.event_queue = event_queue
53
35
  self.response_handler = response_handler
54
36
  self._build_app()
55
37
 
56
38
  def _build_app(self):
57
-
39
+ """Builds FastAPI app and adds endpoints."""
58
40
  @asynccontextmanager
59
41
  async def lifespan(*args, **kwargs):
60
42
  async with self.lifecycle.async_run():
@@ -66,64 +48,48 @@ class NodeServer:
66
48
  version="1.0.0"
67
49
  )
68
50
 
69
- self.router = APIRouter(prefix="/koi-net")
70
51
  self.app.add_exception_handler(ProtocolError, self.protocol_error_handler)
71
52
 
72
- def _add_endpoint(path, func):
53
+ self.router = APIRouter(prefix="/koi-net")
54
+
55
+ for path, models in API_MODEL_MAP.items():
56
+ def create_endpoint(path: str):
57
+ async def endpoint(req):
58
+ return self.response_handler.handle_response(path, req)
59
+
60
+ # programmatically setting type hint annotations for FastAPI's model validation
61
+ endpoint.__annotations__ = {
62
+ "req": models.request_envelope,
63
+ "return": models.response_envelope
64
+ }
65
+
66
+ return endpoint
67
+
73
68
  self.router.add_api_route(
74
69
  path=path,
75
- endpoint=self.secure.envelope_handler(func),
70
+ endpoint=create_endpoint(path),
76
71
  methods=["POST"],
77
72
  response_model_exclude_none=True
78
73
  )
79
74
 
80
- _add_endpoint(BROADCAST_EVENTS_PATH, self.broadcast_events)
81
- _add_endpoint(POLL_EVENTS_PATH, self.poll_events)
82
- _add_endpoint(FETCH_RIDS_PATH, self.fetch_rids)
83
- _add_endpoint(FETCH_MANIFESTS_PATH, self.fetch_manifests)
84
- _add_endpoint(FETCH_BUNDLES_PATH, self.fetch_bundles)
85
-
86
75
  self.app.include_router(self.router)
87
-
88
- def run(self):
89
- uvicorn.run(
90
- app=self.app,
91
- host=self.config.server.host,
92
- port=self.config.server.port
93
- )
94
76
 
95
77
  def protocol_error_handler(self, request, exc: ProtocolError):
96
- logger.info(f"caught protocol error: {exc}")
78
+ """Catches `ProtocolError` and returns as `ErrorResponse`."""
79
+ log.info(f"caught protocol error: {exc}")
97
80
  resp = ErrorResponse(error=exc.error_type)
98
- logger.info(f"returning error response: {resp}")
81
+ log.info(f"returning error response: {resp}")
99
82
  return JSONResponse(
100
83
  status_code=400,
101
84
  content=resp.model_dump(mode="json")
102
85
  )
103
-
104
- async def broadcast_events(self, req: SignedEnvelope[EventsPayload]):
105
- logger.info(f"Request to {BROADCAST_EVENTS_PATH}, received {len(req.payload.events)} event(s)")
106
- for event in req.payload.events:
107
- self.processor.handle(event=event, source=req.source_node)
108
-
109
- async def poll_events(
110
- self, req: SignedEnvelope[PollEvents]
111
- ) -> SignedEnvelope[EventsPayload] | ErrorResponse:
112
- logger.info(f"Request to {POLL_EVENTS_PATH}")
113
- events = self.event_queue.flush_poll_queue(req.source_node)
114
- return EventsPayload(events=events)
115
-
116
- async def fetch_rids(
117
- self, req: SignedEnvelope[FetchRids]
118
- ) -> SignedEnvelope[RidsPayload] | ErrorResponse:
119
- return self.response_handler.fetch_rids(req.payload, req.source_node)
120
-
121
- async def fetch_manifests(
122
- self, req: SignedEnvelope[FetchManifests]
123
- ) -> SignedEnvelope[ManifestsPayload] | ErrorResponse:
124
- return self.response_handler.fetch_manifests(req.payload, req.source_node)
125
-
126
- async def fetch_bundles(
127
- self, req: SignedEnvelope[FetchBundles]
128
- ) -> SignedEnvelope[BundlesPayload] | ErrorResponse:
129
- return self.response_handler.fetch_bundles(req.payload, req.source_node)
86
+
87
+ def run(self):
88
+ """Starts FastAPI server and event handler."""
89
+ uvicorn.run(
90
+ app=self.app,
91
+ host=self.config.server.host,
92
+ port=self.config.server.port,
93
+ log_config=None,
94
+ access_log=False
95
+ )
koi_net/utils.py ADDED
@@ -0,0 +1,18 @@
1
+ from typing import Callable
2
+
3
+ from rid_lib import RID
4
+ from rid_lib.ext import Bundle, Cache
5
+
6
+ cache = Cache()
7
+
8
+ def build_dereferencer(
9
+ *funcs: list[Callable[[RID], Bundle | None]]
10
+ ) -> Callable[[RID], Bundle | None]:
11
+ def any_of(rid: RID):
12
+ return any(
13
+ f(rid) for f in funcs
14
+ )
15
+ return any_of
16
+
17
+ deref = build_dereferencer(cache.read)
18
+ deref(RID.from_string("string:hello_world"))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: koi-net
3
- Version: 1.1.0b8
3
+ Version: 1.2.0b2
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>
@@ -33,14 +33,19 @@ Requires-Dist: httpx>=0.28.1
33
33
  Requires-Dist: networkx>=3.4.2
34
34
  Requires-Dist: pydantic>=2.10.6
35
35
  Requires-Dist: python-dotenv>=1.1.0
36
+ Requires-Dist: rich>=14.1.0
36
37
  Requires-Dist: rid-lib>=3.2.7
37
38
  Requires-Dist: ruamel-yaml>=0.18.10
39
+ Requires-Dist: structlog>=25.4.0
38
40
  Requires-Dist: uvicorn>=0.34.2
39
41
  Provides-Extra: dev
40
42
  Requires-Dist: build; extra == 'dev'
41
43
  Requires-Dist: twine>=6.0; extra == 'dev'
42
- Provides-Extra: examples
43
- Requires-Dist: rich; extra == 'examples'
44
+ Provides-Extra: docs
45
+ Requires-Dist: sphinx; extra == 'docs'
46
+ Requires-Dist: sphinx-autoapi>=3.6.0; extra == 'docs'
47
+ Requires-Dist: sphinx-autodoc-typehints>=3.0.1; extra == 'docs'
48
+ Requires-Dist: sphinx-rtd-theme>=3.0.2; extra == 'docs'
44
49
  Description-Content-Type: text/markdown
45
50
 
46
51
  # KOI-net
@@ -0,0 +1,52 @@
1
+ koi_net/__init__.py,sha256=ZJQHfYaMtu3Qv6ZtKxq49N0T1GbVd3dvrjXZdeNYnQw,41
2
+ koi_net/assembler.py,sha256=kV7qB1xnPvAVUrunaNgx4f9lb2qQlvlA4zZs1xKq62Q,2831
3
+ koi_net/config.py,sha256=yV53GFQrJchyKKRs3sOhj27pyM6rwiUhIgDZ81rvZ48,5238
4
+ koi_net/context.py,sha256=mBKMR1o6Tqy_cyhj7_niGkMSMOQeEMPhP9cpNDlML1s,1323
5
+ koi_net/core.py,sha256=owbJYN_kCMwKz3ecWXt_tQXOEECL_q1uq4CcFAuR6EA,2428
6
+ koi_net/default_actions.py,sha256=y9oaDeb3jJGSvVbuonmyGWkKWlzpEX3V32MjgEuYWc8,622
7
+ koi_net/effector.py,sha256=0hW2NnHWjVZyRPXWh_X_0EBxqpCJBBhJCHFvB6uC3SM,4941
8
+ koi_net/handshaker.py,sha256=sd2bYe7Fh5hCTq5q18_knKWAMzvH5a6zHzCcBKbkhWQ,1229
9
+ koi_net/identity.py,sha256=jZjTSlgO8aJhfOx6-ppQVveHih6h0dP2Gtbsw6GGdTI,569
10
+ koi_net/lifecycle.py,sha256=AhJCkXHuBhUHMXXAzI3akz0pTRE77aNEHwjsnbe98TE,4775
11
+ koi_net/logger.py,sha256=EzpQNvNrbi5LmMCobyuN1_wOz5VuMDeaPbLcyMrLKGI,6172
12
+ koi_net/poller.py,sha256=OZLYAMHxXxM75ENetHd_nnNaiiZTSpMgeP3xxAphVEg,1463
13
+ koi_net/secure.py,sha256=qayAzO7xWF8wa33rmNCTupVVaYXwNuimlXpPFWJfQT8,4911
14
+ koi_net/sentry.py,sha256=9UCVMPoEzua3KMUHe4inciqEnqTF_gNSQO2zhpUN8ts,506
15
+ koi_net/server.py,sha256=GJbkHp2BmDhSHWdF6PObLus7f0BiMZuhcZALj7kNiF4,3087
16
+ koi_net/utils.py,sha256=4K6BqtifExDUfPP8zJAICgPV1mcabz_MaFB0P0fSnic,411
17
+ koi_net/cli/__init__.py,sha256=Vpq0yLN0ROyF0qQYsyiuWFbjs-zsa90G1DpAv13qaiw,25
18
+ koi_net/cli/commands.py,sha256=5eVsvJAnHjwJdt8MNYrk5zSzWWm1ooiP35bJeQxYIq4,2592
19
+ koi_net/cli/models.py,sha256=ON-rqMgHDng3J2hbBbGYzkynaWc9Tq4QfOJIu_6pFuA,1190
20
+ koi_net/interfaces/entrypoint.py,sha256=8FEG1r0YIws_1AojTtIPWB-Th3GOS3U2qi89RlyBJYs,80
21
+ koi_net/interfaces/worker.py,sha256=IvtXBTVmthUrURmB9Cn9wffeVv9_Cphsk97_GCLb5NQ,294
22
+ koi_net/network/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
+ koi_net/network/error_handler.py,sha256=4i_r7EWBW52_bhdmyU-1A_Cnu0Q-jHO9O1EXgO1NGws,1784
24
+ koi_net/network/event_queue.py,sha256=JqSMRk_PvBn5hlnUKF2jl9uxaOCX793fwZsblx-pEKs,743
25
+ koi_net/network/graph.py,sha256=ZJ1CY-SnYhnZAMm3e9YCbBflk80ZDETnoQKaBk5kLgo,4161
26
+ koi_net/network/poll_event_buffer.py,sha256=PO9HnmlhQ0V-uPGOf5b15GhbJtjAzEfMDf6TtsQLtPA,734
27
+ koi_net/network/request_handler.py,sha256=XSX-JAqRua42YOakmia--9NnKcT32Fpoc-7aYfjDpwg,6752
28
+ koi_net/network/resolver.py,sha256=i8YsdIYVo9--YYW5AK9PO-f_lpXIVKZONImJ9wYMySY,5277
29
+ koi_net/network/response_handler.py,sha256=OyEd_5ltQf-sdGDI4QalPuHVLqrSMpAjRQCDtlNR8WU,4216
30
+ koi_net/processor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
+ koi_net/processor/event_worker.py,sha256=z6Zef5TFDokwywSNzaMh6oDmEaAoss6m--dRHHmU3YY,4190
32
+ koi_net/processor/handler.py,sha256=PJlQCPfKm3zYsJrwmGIw5xZmc6vArKz_UoeJuXBj16Y,2356
33
+ koi_net/processor/handlers.py,sha256=rGvjrud72szKBM8rhZRrQ2qO8Ng97oGLIfUG9Af-oxw,10934
34
+ koi_net/processor/knowledge_object.py,sha256=0VyBOqkCoINMK3fqYhLlXU-Ri7gKEpJloDHfhaGITxg,4172
35
+ koi_net/processor/kobj_queue.py,sha256=A4jdS0WCrL-fg3Kl8bHPbzIjSfYNGOBBqzCbSJhfMZ4,1837
36
+ koi_net/processor/kobj_worker.py,sha256=26DG8fU3hLbKZmS6mcuOEnUWcVLkq-1fl8AGNLrYFY0,1237
37
+ koi_net/processor/pipeline.py,sha256=FpU3nORIeJxJuX8QHTSqIji8iMU69GuTR4UMeThOzUo,8668
38
+ koi_net/protocol/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
+ koi_net/protocol/api_models.py,sha256=lPd_w-sncyrQlTQ__iae9Li1lFARu8nKiMMlXu7-Hls,1856
40
+ koi_net/protocol/consts.py,sha256=bisbVEojPIHlLhkLafBzfIhH25TjNfvTORF1g6YXzIM,243
41
+ koi_net/protocol/edge.py,sha256=PzdEhC43T1KO5iMSEu7I4tiz-7sZxtz41dJfWf-oHA0,1034
42
+ koi_net/protocol/envelope.py,sha256=4SKF4tP1P1ex7UEmYOJt7IP9_8fCWsa_o6ZBOu8SOKk,1877
43
+ koi_net/protocol/errors.py,sha256=uKPQ-TGLouZuK0xd2pXuCQoRTyu_JFsydSCLml13Cz8,595
44
+ koi_net/protocol/event.py,sha256=HxzLN-iCXPyr2YzrswMIkgZYeUdFbBpa5v98dAB06lQ,1328
45
+ koi_net/protocol/model_map.py,sha256=W0quo25HqVkzp8HQ7l_FNTtN4ZX0u7MIqp68Ir81fuk,1671
46
+ koi_net/protocol/node.py,sha256=KH_SjHDzW-V4pn2tqpTDhIzfuCgKgM1YqCafyofLN3k,466
47
+ koi_net/protocol/secure.py,sha256=y3-l0ldQ4oQ6ReEmunDy0ncF836kZvLdGFeEgmuJw44,5110
48
+ koi_net-1.2.0b2.dist-info/METADATA,sha256=t4T3T0cGyG24XvptQg6vy10B8_gHCWGW-s0PntA9aX8,37347
49
+ koi_net-1.2.0b2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
50
+ koi_net-1.2.0b2.dist-info/entry_points.txt,sha256=l7He_JTyXrfKIHkttnPWXHI717v8WpLLfCduL5QcEWA,40
51
+ koi_net-1.2.0b2.dist-info/licenses/LICENSE,sha256=03mgCL5qth2aD9C3F3qNVs4sFJSpK9kjtYCyOwdSp7s,1069
52
+ koi_net-1.2.0b2.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ koi = koi_net.cli:app
koi_net/actor.py DELETED
@@ -1,60 +0,0 @@
1
- from logging import getLogger
2
- from rid_lib.types import KoiNetNode
3
- from rid_lib import RIDType
4
- from koi_net.context import HandlerContext
5
- from koi_net.protocol.api_models import ErrorResponse
6
- from .protocol.event import Event, EventType
7
-
8
-
9
- logger = getLogger(__name__)
10
-
11
-
12
- class Actor:
13
- ctx: HandlerContext
14
-
15
- def __init__(self):
16
- pass
17
-
18
- def set_ctx(self, ctx: HandlerContext):
19
- self.ctx = ctx
20
-
21
- def handshake_with(self, target: KoiNetNode):
22
- logger.debug(f"Initiating handshake with {target}")
23
- self.ctx.event_queue.push_event_to(
24
- Event.from_rid(
25
- event_type=EventType.FORGET,
26
- rid=self.ctx.identity.rid),
27
- node=target
28
- )
29
-
30
- self.ctx.event_queue.push_event_to(
31
- event=Event.from_bundle(
32
- event_type=EventType.NEW,
33
- bundle=self.ctx.effector.deref(self.ctx.identity.rid)),
34
- node=target
35
- )
36
-
37
- self.ctx.event_queue.flush_webhook_queue(target)
38
-
39
- def identify_coordinators(self):
40
- return self.ctx.resolver.get_state_providers(KoiNetNode)
41
-
42
- def catch_up_with(self, target: KoiNetNode, rid_types: list[RIDType] = []):
43
- logger.debug(f"catching up with {target} on {rid_types or 'all types'}")
44
-
45
- payload = self.ctx.request_handler.fetch_manifests(
46
- node=target,
47
- rid_types=rid_types
48
- )
49
- if type(payload) == ErrorResponse:
50
- logger.debug("failed to reach node")
51
- return
52
-
53
- for manifest in payload.manifests:
54
- if manifest.rid == self.ctx.identity.rid:
55
- continue
56
-
57
- self.ctx.handle(
58
- manifest=manifest,
59
- source=target
60
- )
@@ -1,101 +0,0 @@
1
- import logging
2
- import queue
3
- import threading
4
- from rid_lib.core import RID
5
- from rid_lib.ext import Bundle, Manifest
6
- from rid_lib.types import KoiNetNode
7
- from ..protocol.event import Event, EventType
8
- from .knowledge_object import KnowledgeObject
9
- from .knowledge_pipeline import KnowledgePipeline
10
-
11
-
12
- logger = logging.getLogger(__name__)
13
-
14
-
15
- class ProcessorInterface:
16
- """Provides access to this node's knowledge processing pipeline."""
17
- pipeline: KnowledgePipeline
18
- kobj_queue: queue.Queue[KnowledgeObject]
19
- use_kobj_processor_thread: bool
20
- worker_thread: threading.Thread | None = None
21
-
22
- def __init__(
23
- self,
24
- pipeline: KnowledgePipeline,
25
- use_kobj_processor_thread: bool,
26
- ):
27
- self.pipeline = pipeline
28
- self.use_kobj_processor_thread = use_kobj_processor_thread
29
- self.kobj_queue = queue.Queue()
30
-
31
- if self.use_kobj_processor_thread:
32
- self.worker_thread = threading.Thread(
33
- target=self.kobj_processor_worker,
34
- daemon=True
35
- )
36
-
37
- def flush_kobj_queue(self):
38
- """Flushes all knowledge objects from queue and processes them.
39
-
40
- NOTE: ONLY CALL THIS METHOD IN SINGLE THREADED NODES, OTHERWISE THIS WILL CAUSE RACE CONDITIONS.
41
- """
42
- if self.use_kobj_processor_thread:
43
- logger.warning("You are using a worker thread, calling this method can cause race conditions!")
44
-
45
- while not self.kobj_queue.empty():
46
- kobj = self.kobj_queue.get()
47
- logger.debug(f"Dequeued {kobj!r}")
48
-
49
- try:
50
- self.pipeline.process(kobj)
51
- finally:
52
- self.kobj_queue.task_done()
53
- logger.debug("Done")
54
-
55
- def kobj_processor_worker(self, timeout=0.1):
56
- while True:
57
- try:
58
- kobj = self.kobj_queue.get(timeout=timeout)
59
- logger.debug(f"Dequeued {kobj!r}")
60
-
61
- try:
62
- self.pipeline.process(kobj)
63
- finally:
64
- self.kobj_queue.task_done()
65
- logger.debug("Done")
66
-
67
- except queue.Empty:
68
- pass
69
-
70
- except Exception as e:
71
- logger.warning(f"Error processing kobj: {e}")
72
-
73
- def handle(
74
- self,
75
- rid: RID | None = None,
76
- manifest: Manifest | None = None,
77
- bundle: Bundle | None = None,
78
- event: Event | None = None,
79
- kobj: KnowledgeObject | None = None,
80
- event_type: EventType | None = None,
81
- source: KoiNetNode | None = None
82
- ):
83
- """Queues provided knowledge to be handled by processing pipeline.
84
-
85
- Knowledge may take the form of an RID, manifest, bundle, event, or knowledge object (with an optional event type for RID, manifest, or bundle objects). All objects will be normalized into knowledge objects and queued. If `flush` is `True`, the queue will be flushed immediately after adding the new knowledge.
86
- """
87
- if rid:
88
- _kobj = KnowledgeObject.from_rid(rid, event_type, source)
89
- elif manifest:
90
- _kobj = KnowledgeObject.from_manifest(manifest, event_type, source)
91
- elif bundle:
92
- _kobj = KnowledgeObject.from_bundle(bundle, event_type, source)
93
- elif event:
94
- _kobj = KnowledgeObject.from_event(event, source)
95
- elif kobj:
96
- _kobj = kobj
97
- else:
98
- raise ValueError("One of 'rid', 'manifest', 'bundle', 'event', or 'kobj' must be provided")
99
-
100
- self.kobj_queue.put(_kobj)
101
- logger.debug(f"Queued {_kobj!r}")
@@ -1,38 +0,0 @@
1
- koi_net/__init__.py,sha256=b0Ze0pZmJAuygpWUFHM6Kvqo3DkU_uzmkptv1EpAArw,31
2
- koi_net/actor.py,sha256=Gad1Xg8n_-zm6sj0nDkm_B1MwErQJKeUsbGmIDTRqJk,1820
3
- koi_net/config.py,sha256=47XbQ59GRYFi4rlsoWKlnzMQATcnK70i3qmKTZAGOQk,4087
4
- koi_net/context.py,sha256=G067ecIJJ5k8aesdyxjZC_vh3zVg9PR_H2U-09YIxXA,1683
5
- koi_net/core.py,sha256=6nEDAOkMTv-pynU_hLOG4tKVWhopMPIHyZI6oJTdLj8,7061
6
- koi_net/default_actions.py,sha256=TkQR9oj9CpO37Gb5bZLmFNl-Q8n3OxGiX4dvxQR7SaA,421
7
- koi_net/effector.py,sha256=gSyZgRxQ91X04UL261e2pXWUfBHnQTGtjSHpc2JufxA,4097
8
- koi_net/identity.py,sha256=FvIWksGTqwM7HCevIwmo_6l-t-2tnYkaaR4CanZatL4,569
9
- koi_net/lifecycle.py,sha256=1WCo-VOox0rK3v_lfzhnFMGiyacZJpsaENlyGq7jHJQ,3563
10
- koi_net/poller.py,sha256=bIrlqdac5vLQYAid35xiQJLDMR85GnOSPCXSTQ07-Mc,1173
11
- koi_net/secure.py,sha256=cGNF2assqCaYq0i0fhQBm7aREoAdpY-XVypDsE1ALaU,3970
12
- koi_net/server.py,sha256=PrR_cXQV5YMKa6FXwiJXwMZJ52VQVzLPYYPVl-Miuw8,4315
13
- koi_net/network/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- koi_net/network/error_handler.py,sha256=09ulFPpSzoI49RFYPxc5TLXslqJQ_78q7TzLJIABeMw,1606
15
- koi_net/network/event_queue.py,sha256=DWs26C235iYkP4koKcdbhmIOHGZRJ48d072BoNWyiHo,7325
16
- koi_net/network/graph.py,sha256=neVVVHSyqsQR8hW2-lLC8IkDC2xciBXh3aWYXQpVqZs,4134
17
- koi_net/network/request_handler.py,sha256=_SM5MuYkS636wGJeFkesapQsW5x_kt_1o9KTXB0wksU,6869
18
- koi_net/network/resolver.py,sha256=YpQq6HKyfcoqr9TnHRnlQI33IM3tE0ljU02pZ3wWLh8,5410
19
- koi_net/network/response_handler.py,sha256=__R_EvEpjaMz3PCDvkNgWF_EAHe2nePGk-zK_cT4C4g,2077
20
- koi_net/processor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
- koi_net/processor/default_handlers.py,sha256=1OTC4p0luTadNm90q6Fr_dbvysFzgRCbltp-YP6cRXo,9562
22
- koi_net/processor/handler.py,sha256=_loaHjgVGVUxtCQdvAY9dQ0iqiq5co7wB2tK-usuv3Y,2355
23
- koi_net/processor/interface.py,sha256=ebDwqggznFRfp2PT8-UJPUAvCwX8nZaaQ68FUeWQvmw,3682
24
- koi_net/processor/knowledge_object.py,sha256=avQnsaeqqiJxy40P1VGljuQMtAGmJB-TBa4pmBXTaIs,3863
25
- koi_net/processor/knowledge_pipeline.py,sha256=i7FpCFl0UIOwCI5zhP1i8M4PX4A48VN28iV9jruvN5k,9486
26
- koi_net/protocol/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
- koi_net/protocol/api_models.py,sha256=jzRZWW_ZB5YsBAiwCom882-WIbr0rPyelJxExRgHZGc,1755
28
- koi_net/protocol/consts.py,sha256=bisbVEojPIHlLhkLafBzfIhH25TjNfvTORF1g6YXzIM,243
29
- koi_net/protocol/edge.py,sha256=PzdEhC43T1KO5iMSEu7I4tiz-7sZxtz41dJfWf-oHA0,1034
30
- koi_net/protocol/envelope.py,sha256=UVHlO2BDyDiP5eixqx9xD6xUsCfFRi0kZyzC4BC-DOw,1886
31
- koi_net/protocol/errors.py,sha256=uKPQ-TGLouZuK0xd2pXuCQoRTyu_JFsydSCLml13Cz8,595
32
- koi_net/protocol/event.py,sha256=HxzLN-iCXPyr2YzrswMIkgZYeUdFbBpa5v98dAB06lQ,1328
33
- koi_net/protocol/node.py,sha256=7GQzHORFr9cP4BqJgir6EGSWCskL-yqmvJksIiLfcWU,409
34
- koi_net/protocol/secure.py,sha256=6sRLWxG5EDF0QLBj29gk3hPmZnPXATrTTFdwx39wQfY,5127
35
- koi_net-1.1.0b8.dist-info/METADATA,sha256=Kcb1WYE-Eu04rmqyapoF_D_BzfO7q3Q8rSd_dLnXQcY,37118
36
- koi_net-1.1.0b8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
37
- koi_net-1.1.0b8.dist-info/licenses/LICENSE,sha256=03mgCL5qth2aD9C3F3qNVs4sFJSpK9kjtYCyOwdSp7s,1069
38
- koi_net-1.1.0b8.dist-info/RECORD,,