sync_http — Network¶
Version: 19.0.0.3.0 · Depends: sync_base · License: OPL-1
sync_http adds native Odoo-to-Odoo delivery to the Sync framework — no sidecar daemon required.
Each gateway authenticates with a Bearer token and POSTs directly to the target instance’s REST endpoint.
Architecture¶
In a sync_http swarm, one node is designated as the gateway (local Odoo instance).
The gateway fans out outbound events to every non-gateway node using that node’s own API key — the receiving Odoo matches the key to a local res.users and applies its own access rules.
Gateway (local Odoo)
│
├── POST /odoo_sync/v0/push → Node A (Bearer: node-a-secret)
└── POST /odoo_sync/v0/push → Node B (Bearer: node-b-secret)
Delivery is synchronous per node: the gateway POSTs and waits for {"status": "admitted"} before marking the event as sent.
For pull delivery (deliver_mode = pull), remote nodes poll /odoo_sync/v0/pull on a schedule instead; this is driven by ip.swarm._http_pull_sweep().
CID Blobs¶
Binary payloads are not embedded in events. Events carry CID identifiers; blobs are served on demand via two HTTP endpoints:
Endpoint |
Auth / caller |
|---|---|
|
Bearer token. Remote nodes call this via |
|
Odoo session cookie. Local Odoo users viewing attachments in the browser. |
ip.node.add() stores a blob and returns its CID (SHA-1 hash of the content).
ip.node.cat() fetches a blob by CID from the node’s ip.node.odoo_url and caches the result in cid.
See also
sync_http — full SyncHttpController endpoint reference.
HTTP Transport — delivery modes, routing modes, and setup checklist.
Models¶
- class ip.swarm[source]¶
HTTP transport implementation of the network dispatch and CID fetch hooks.
Outbound Dispatch
- _dispatch_events(events)[source]¶
Fan-out outbound events to HTTP peers in a background thread.
Groups events by their reference node (
to_node_idfor direct,from_node_idfor broadcast), marks events with no resolvable node asfailed, then spawns a daemon thread that POSTs each group to its target peer using_http_send_events().Returns
Noneimmediately — delivery confirmation is asynchronous.
CID Fetching
- _do_express_fetch_cids(cids)[source]¶
Spawn a background thread to fetch each wanted CID from its HTTP host node.
Cron Sync
- _http_fetch_wanted_cids()[source]¶
Cron entry-point: find all wanted CIDs whose host node is an HTTP node and trigger an express fetch for each swarm group.
- _http_pull_sweep()[source]¶
Cron entry-point: poll all online HTTP peers for new inbound events.
For each active HTTP swarm, queries every online non-gateway node at its /odoo_sync/v0/pull endpoint, submits the returned payloads through the standard sync push pipeline, then stores the node’s reported last_sync.
Thread functions
These non-method functions are called by ip.swarm to handle background tasks.
- sync_http._http_dispatch_thread()[source]¶
Background thread: deliver pre-built HTTP payloads and mark events sent/failed.
node_groups: {node_id: {“event_ids”: […], “payloads”: […]}}
- sync_http._http_fetch_thread()[source]¶
Background thread: fetch raw CID bytes from each CID’s host node and pin locally.
- class ip.node[source]¶
Native HTTP transport extension for ip.node.
Attributes
- odoo_url: fields.Char[source]¶
- Base URL of the remote Odoo instance (e.g. https://acme.odoo.com).
Heartbeat Lifecycle
Content Addressing
- add(payload)[source]¶
Store payload locally and return the pinned
ip.cidrecord.Creates an
ip.cidrecord (state=pinned) with the raw bytes stored indata_raw(afields.Binary(attachment=True)managed by Odoo’s ORM). Idempotent: repeated calls with identical bytes return the same record.- Parameters:
payload – Raw content to store (
bytesorstr).- Returns:
The
ip.cidrecord, orNoneon failure.
- cat(cid: str | models.BaseModel) bytes | None[source]¶
Fetch content by CID (SHA-1 checksum).
All nodes: returns
data_rawif present in the local filestore.Gateway node: returns
Noneon a local cache miss (no outbound fetch).Remote node: falls back to
GET /odoo_sync/v0/blob/<cid>on the peer’sodoo_urlwhen the data is not cached locally.
- Parameters:
cid – CID string or
ip.cidrecord. Whencidis a string, a DB lookup is done to find the matchingip.cidrecord.- Returns:
Raw bytes of the content, or
Noneif not found / unreachable.
Transport Interface
- _http_request(method: str, endpoint: str, timeout=(3.0, 15.0), **kwargs)[source]¶
Issue an HTTP request to odoo_url + endpoint.
Checks
odoo_urlis configured, builds the full URL, injects theAuthorizationheader and dispatches. All network errors are caught, logged, and collapsed toNoneso callers need no try/except of their own.- Returns:
Responseobject (any HTTP status), orNoneon network error or missing URL.
- _http_request_json(endpoint: str, params: dict, timeout=(3.0, 15.0))[source]¶
JSON-RPC POST to odoo_url + endpoint with params as the call arguments.
- _http_send_events(payloads: list[dict]) bool[source]¶
Deliver payloads to the network.
Gateway node: fans out to all non-gateway HTTP nodes in the swarm, each called with its own
odoo_api_key. ReturnsTruevacuously when there are no peers,Trueif at least one peer was reached,Falseonly when every peer was unreachable.Non-gateway node: POSTs directly to
/odoo_sync/v0/pushon this node’s ownodoo_url.
- Parameters:
payloads – List of event payload dicts to deliver.
- Returns:
Trueif the network was reached,Falseif every target was completely unreachable.
Connectivity