mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-11-12 05:08:09 +00:00
agent: use double ratchet from the first message in contact addresses, request rejection, RPC (#1831)
* agent: initialize double ratchet from the invitation via contact address (#1829) * rfc: agent support for PRC pattern without duplex connection * update rfc, plan * corrections Co-authored-by: Evgeny <evgeny@poberezkin.com> * split rfcs, add plan * update rfc * update rfc and plan * update plan * add double ratchet keys to address * agent schema * fix version in test * change ContactRequest encoding * fix tests * update plan * tests, refactor * fix compilation * refactor * refactor more * fix * add export * fix * refactor * refactor * update schema * rename * refactor * refactor 2 * comment, type * type * rename * refactor more * move type * refactor * remove comment * diff * refactor * comment * puns * get correct key * rename * add autoincrement * refactor * move * move back * simplify * rename * refactor * tuple * comment * split decryption * refactor * rename * refactor * move * remove createSndQueue * remove comment * remove JoinInvitationReq * simplify * rename * fix * type synonim * getConnData * simplify * move * encoding * version * async join with ratchet keys * fix encoding * rotate address ratchet keys * rename, parameter order * refactor, include ratchet keys into ConnectionRequestUri * simplify * remove records * refactor * rename, encoding * clean up * refactor * compatible * addrKeysE2EVersion * support IKUsePQ for contact addresses * comments, refactor condition * typos --------- Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com> * agent: contact request rejection and service requests (#1833) * agent: request rejection * implement RPC requests/responses * simplify rpc, test, async * renames * clean up * fix * fix query * set flag at creation * move * command type, schema * rename * refactor * typo Co-authored-by: simplex-chat-agent[bot] <287173099+simplex-chat-agent[bot]@users.noreply.github.com> * allow overriding the service request timeout per request * fixes * use SSENT event for service replies * AgentServiceError encoding * sign service requests * add bad signature error * update the plan * clean up * refactor * empty line Co-authored-by: simplex-chat-agent[bot] <287173099+simplex-chat-agent[bot]@users.noreply.github.com> * add indices --------- Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com> Co-authored-by: simplex-chat-agent[bot] <287173099+simplex-chat-agent[bot]@users.noreply.github.com> * update schemas * tryAllErrors * combine queries --------- Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com> Co-authored-by: simplex-chat-agent[bot] <287173099+simplex-chat-agent[bot]@users.noreply.github.com>
This commit is contained in:
31 files changed
+2382
-390
No files matched your search
@@ -13,6 +13,7 @@ import Simplex.Messaging.Agent.Store.Postgres.Migrations.M20251010_client_notice
|
||||
import Simplex.Messaging.Agent.Store.Postgres.Migrations.M20251230_strict_tables
|
||||
import Simplex.Messaging.Agent.Store.Postgres.Migrations.M20260410_receive_attempts
|
||||
import Simplex.Messaging.Agent.Store.Postgres.Migrations.M20260411_service_certs
|
||||
import Simplex.Messaging.Agent.Store.Postgres.Migrations.M20260712_address_dr_rpc
|
||||
import Simplex.Messaging.Agent.Store.Shared (Migration (..))
|
||||
|
||||
schemaMigrations :: [(String, Text, Maybe Text)]
|
||||
@@ -25,7 +26,8 @@ schemaMigrations =
|
||||
("20251010_client_notices", m20251010_client_notices, Just down_m20251010_client_notices),
|
||||
("20251230_strict_tables", m20251230_strict_tables, Just down_m20251230_strict_tables),
|
||||
("20260410_receive_attempts", m20260410_receive_attempts, Just down_m20260410_receive_attempts),
|
||||
("20260411_service_certs", m20260411_service_certs, Just down_m20260411_service_certs)
|
||||
("20260411_service_certs", m20260411_service_certs, Just down_m20260411_service_certs),
|
||||
("20260712_address_dr_rpc", m20260712_address_dr_rpc, Just down_m20260712_address_dr_rpc)
|
||||
]
|
||||
|
||||
-- | The list of migrations in ascending order by date
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Simplex.Messaging.Agent.Store.Postgres.Migrations.M20260712_address_dr_rpc where
|
||||
|
||||
import Data.Text (Text)
|
||||
import Text.RawString.QQ (r)
|
||||
|
||||
m20260712_address_dr_rpc :: Text
|
||||
m20260712_address_dr_rpc =
|
||||
[r|
|
||||
CREATE TABLE address_ratchet_keys(
|
||||
address_ratchet_key_id BIGSERIAL PRIMARY KEY,
|
||||
conn_id BYTEA NOT NULL REFERENCES connections ON DELETE CASCADE,
|
||||
ratchet_key_id BYTEA NOT NULL,
|
||||
x3dh_priv_key_1 BYTEA NOT NULL,
|
||||
x3dh_priv_key_2 BYTEA NOT NULL,
|
||||
pq_priv_kem BYTEA,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT (now())
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_address_ratchet_keys ON address_ratchet_keys(conn_id, ratchet_key_id);
|
||||
|
||||
ALTER TABLE conn_invitations ADD COLUMN service_request SMALLINT NOT NULL DEFAULT 0; -- service side: received request is a service request (SREQ) not a contact request (REQ)
|
||||
ALTER TABLE connections ADD COLUMN created_at TIMESTAMPTZ NOT NULL DEFAULT '1970-01-01 00:00:00';
|
||||
ALTER TABLE connections ADD COLUMN service_request_expires_at TIMESTAMPTZ; -- client side: requester's outstanding service request; the time the client stops waiting for the response
|
||||
|
||||
CREATE INDEX idx_connections_deleted ON connections(deleted);
|
||||
CREATE INDEX idx_connections_service_request_expires_at ON connections(service_request_expires_at);
|
||||
|]
|
||||
|
||||
down_m20260712_address_dr_rpc :: Text
|
||||
down_m20260712_address_dr_rpc =
|
||||
[r|
|
||||
DROP INDEX idx_connections_service_request_expires_at;
|
||||
DROP INDEX idx_connections_deleted;
|
||||
ALTER TABLE connections DROP COLUMN service_request_expires_at;
|
||||
ALTER TABLE connections DROP COLUMN created_at;
|
||||
ALTER TABLE conn_invitations DROP COLUMN service_request;
|
||||
DROP INDEX idx_address_ratchet_keys;
|
||||
DROP TABLE address_ratchet_keys;
|
||||
|]
|
||||
@@ -104,6 +104,31 @@ CREATE AGGREGATE smp_agent_test_protocol_schema.xor_aggregate(bytea) (
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
|
||||
CREATE TABLE smp_agent_test_protocol_schema.address_ratchet_keys (
|
||||
address_ratchet_key_id bigint NOT NULL,
|
||||
conn_id bytea NOT NULL,
|
||||
ratchet_key_id bytea NOT NULL,
|
||||
x3dh_priv_key_1 bytea NOT NULL,
|
||||
x3dh_priv_key_2 bytea NOT NULL,
|
||||
pq_priv_kem bytea,
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
|
||||
|
||||
|
||||
CREATE SEQUENCE smp_agent_test_protocol_schema.address_ratchet_keys_address_ratchet_key_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
|
||||
ALTER SEQUENCE smp_agent_test_protocol_schema.address_ratchet_keys_address_ratchet_key_id_seq OWNED BY smp_agent_test_protocol_schema.address_ratchet_keys.address_ratchet_key_id;
|
||||
|
||||
|
||||
|
||||
CREATE TABLE smp_agent_test_protocol_schema.client_notices (
|
||||
client_notice_id bigint NOT NULL,
|
||||
protocol text NOT NULL,
|
||||
@@ -194,7 +219,8 @@ CREATE TABLE smp_agent_test_protocol_schema.conn_invitations (
|
||||
recipient_conn_info bytea NOT NULL,
|
||||
accepted smallint DEFAULT 0 NOT NULL,
|
||||
own_conn_info bytea,
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||
service_request smallint DEFAULT 0 NOT NULL
|
||||
);
|
||||
|
||||
|
||||
@@ -215,7 +241,9 @@ CREATE TABLE smp_agent_test_protocol_schema.connections (
|
||||
user_id bigint NOT NULL,
|
||||
ratchet_sync_state text DEFAULT 'ok'::text NOT NULL,
|
||||
deleted_at_wait_delivery timestamp with time zone,
|
||||
pq_support smallint DEFAULT 0 NOT NULL
|
||||
pq_support smallint DEFAULT 0 NOT NULL,
|
||||
created_at timestamp with time zone DEFAULT '1970-01-01 00:00:00+01'::timestamp with time zone NOT NULL,
|
||||
service_request_expires_at timestamp with time zone
|
||||
);
|
||||
|
||||
|
||||
@@ -847,6 +875,15 @@ ALTER TABLE smp_agent_test_protocol_schema.xftp_servers ALTER COLUMN xftp_server
|
||||
|
||||
|
||||
|
||||
ALTER TABLE ONLY smp_agent_test_protocol_schema.address_ratchet_keys ALTER COLUMN address_ratchet_key_id SET DEFAULT nextval('smp_agent_test_protocol_schema.address_ratchet_keys_address_ratchet_key_id_seq'::regclass);
|
||||
|
||||
|
||||
|
||||
ALTER TABLE ONLY smp_agent_test_protocol_schema.address_ratchet_keys
|
||||
ADD CONSTRAINT address_ratchet_keys_pkey PRIMARY KEY (address_ratchet_key_id);
|
||||
|
||||
|
||||
|
||||
ALTER TABLE ONLY smp_agent_test_protocol_schema.client_notices
|
||||
ADD CONSTRAINT client_notices_pkey PRIMARY KEY (client_notice_id);
|
||||
|
||||
@@ -1032,6 +1069,10 @@ ALTER TABLE ONLY smp_agent_test_protocol_schema.xftp_servers
|
||||
|
||||
|
||||
|
||||
CREATE UNIQUE INDEX idx_address_ratchet_keys ON smp_agent_test_protocol_schema.address_ratchet_keys USING btree (conn_id, ratchet_key_id);
|
||||
|
||||
|
||||
|
||||
CREATE UNIQUE INDEX idx_client_notices_entity ON smp_agent_test_protocol_schema.client_notices USING btree (protocol, host, port, entity_id);
|
||||
|
||||
|
||||
@@ -1056,6 +1097,14 @@ CREATE INDEX idx_conn_invitations_contact_conn_id ON smp_agent_test_protocol_sch
|
||||
|
||||
|
||||
|
||||
CREATE INDEX idx_connections_deleted ON smp_agent_test_protocol_schema.connections USING btree (deleted);
|
||||
|
||||
|
||||
|
||||
CREATE INDEX idx_connections_service_request_expires_at ON smp_agent_test_protocol_schema.connections USING btree (service_request_expires_at);
|
||||
|
||||
|
||||
|
||||
CREATE INDEX idx_connections_user ON smp_agent_test_protocol_schema.connections USING btree (user_id);
|
||||
|
||||
|
||||
@@ -1268,6 +1317,11 @@ CREATE TRIGGER tr_rcv_queue_update AFTER UPDATE ON smp_agent_test_protocol_schem
|
||||
|
||||
|
||||
|
||||
ALTER TABLE ONLY smp_agent_test_protocol_schema.address_ratchet_keys
|
||||
ADD CONSTRAINT address_ratchet_keys_conn_id_fkey FOREIGN KEY (conn_id) REFERENCES smp_agent_test_protocol_schema.connections(conn_id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
|
||||
ALTER TABLE ONLY smp_agent_test_protocol_schema.client_services
|
||||
ADD CONSTRAINT client_services_host_port_fkey FOREIGN KEY (host, port) REFERENCES smp_agent_test_protocol_schema.servers(host, port) ON DELETE RESTRICT;
|
||||
|
||||
|
||||
Reference in new issue
Block a user