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

/odoo_sync/v0/blob/<cid>

Bearer token. Remote nodes call this via ip.node.cat().

/odoo_sync/blob/<cid>/<filename>

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_id for direct, from_node_id for broadcast), marks events with no resolvable node as failed, then spawns a daemon thread that POSTs each group to its target peer using _http_send_events().

Returns None immediately — 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).
odoo_api_key: fields.Char[source]
Bearer token used to authenticate with the remote Odoo instance.

Heartbeat Lifecycle

_heartbeat_reap()[source]

HTTP gateways self-probe before the reap cycle to maintain liveness.

Content Addressing

add(payload)[source]

Store payload locally and return the pinned ip.cid record.

Creates an ip.cid record (state=pinned) with the raw bytes stored in data_raw (a fields.Binary(attachment=True) managed by Odoo’s ORM). Idempotent: repeated calls with identical bytes return the same record.

Parameters:

payload – Raw content to store (bytes or str).

Returns:

The ip.cid record, or None on failure.

cat(cid: str | models.BaseModel) → bytes | None[source]

Fetch content by CID (SHA-1 checksum).

  • All nodes: returns data_raw if present in the local filestore.

  • Gateway node: returns None on a local cache miss (no outbound fetch).

  • Remote node: falls back to GET /odoo_sync/v0/blob/<cid> on the peer’s odoo_url when the data is not cached locally.

Parameters:

cid – CID string or ip.cid record. When cid is a string, a DB lookup is done to find the matching ip.cid record.

Returns:

Raw bytes of the content, or None if 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_url is configured, builds the full URL, injects the Authorization header and dispatches. All network errors are caught, logged, and collapsed to None so callers need no try/except of their own.

Returns:

Response object (any HTTP status), or None on 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. Returns True vacuously when there are no peers, True if at least one peer was reached, False only when every peer was unreachable.

  • Non-gateway node: POSTs directly to /odoo_sync/v0/push on this node’s own odoo_url.

Parameters:

payloads – List of event payload dicts to deliver.

Returns:

True if the network was reached, False if every target was completely unreachable.

Connectivity

_fetch_identity()[source]

Ping each HTTP node’s Odoo instance to confirm connectivity.

Returns the subset of nodes successfully reached. Logs warnings for failures instead of raising, to support the polymorphic loopback-probe pattern.


class ip.cid[source]

Triggers an express CID fetch immediately on creation.

Overrides create() so that new wanted CID records in HTTP swarms are dispatched to the express-fetch endpoint right away rather than waiting for the next pull-sweep cron cycle.