veilid/veilid-core/proto/veilid.capnp

538 lines
21 KiB
Cap'n Proto
Raw Normal View History

2021-11-22 11:28:30 -05:00
@0x8ffce8033734ab02;
# IDs And Hashes
##############################
struct Curve25519PublicKey {
u0 @0 :UInt64;
u1 @1 :UInt64;
u2 @2 :UInt64;
u3 @3 :UInt64;
}
struct Ed25519Signature {
u0 @0 :UInt64;
u1 @1 :UInt64;
u2 @2 :UInt64;
u3 @3 :UInt64;
u4 @4 :UInt64;
u5 @5 :UInt64;
u6 @6 :UInt64;
u7 @7 :UInt64;
}
struct XChaCha20Poly1305Nonce {
u0 @0 :UInt64;
u1 @1 :UInt64;
u2 @2 :UInt64;
}
struct BLAKE3Hash {
u0 @0 :UInt64;
u1 @1 :UInt64;
u2 @2 :UInt64;
u3 @3 :UInt64;
}
using NodeID = Curve25519PublicKey;
using RoutePublicKey = Curve25519PublicKey;
using ValueID = Curve25519PublicKey;
using Nonce = XChaCha20Poly1305Nonce;
using Signature = Ed25519Signature;
using BlockID = BLAKE3Hash;
using TunnelID = UInt64;
# Node Dial Info
################################################################
struct AddressIPV4 {
addr @0 :UInt32; # Address in big endian format
}
struct AddressIPV6 {
addr0 @0 :UInt32; # \
addr1 @1 :UInt32; # \ Address in big
addr2 @2 :UInt32; # / endian format
addr3 @3 :UInt32; # /
}
struct Address {
union {
ipv4 @0 :AddressIPV4;
ipv6 @1 :AddressIPV6;
}
}
struct SocketAddress {
2021-12-20 19:12:30 -05:00
address @0 :Address;
port @1 :UInt16;
2021-11-22 11:28:30 -05:00
}
enum ProtocolKind {
udp @0;
ws @1;
wss @2;
tcp @3;
}
struct DialInfoUDP {
2021-12-20 19:12:30 -05:00
socketAddress @0 :SocketAddress;
2021-11-22 11:28:30 -05:00
}
struct DialInfoTCP {
2021-12-20 19:12:30 -05:00
socketAddress @0 :SocketAddress;
2021-11-22 11:28:30 -05:00
}
struct DialInfoWS {
2021-12-20 19:12:30 -05:00
socketAddress @0 :SocketAddress;
request @1 :Text;
2021-11-22 11:28:30 -05:00
}
struct DialInfoWSS {
2021-12-20 19:12:30 -05:00
socketAddress @0 :SocketAddress;
request @1 :Text;
2021-11-22 11:28:30 -05:00
}
struct DialInfo {
union {
udp @0 :DialInfoUDP;
tcp @1 :DialInfoTCP;
ws @2 :DialInfoWS;
wss @3 :DialInfoWSS;
}
}
2021-12-31 22:09:30 -05:00
struct NodeDialInfo {
2021-11-22 11:28:30 -05:00
nodeId @0 :NodeID; # node id
dialInfo @1 :DialInfo; # how to get to the node
}
2022-04-16 11:18:54 -04:00
# Signals
##############################
struct SignalInfoHolePunch {
2022-05-28 16:11:50 -04:00
receipt @0 :Data; # receipt to return with hole punch
2022-04-17 13:28:39 -04:00
peerInfo @1 :PeerInfo; # peer info of the signal sender for hole punch attempt
2022-04-16 11:18:54 -04:00
}
struct SignalInfoReverseConnect {
2022-05-28 16:11:50 -04:00
receipt @0 :Data; # receipt to return with reverse connect
2022-04-17 13:28:39 -04:00
peerInfo @1 :PeerInfo; # peer info of the signal sender for reverse connect attempt
2022-04-16 11:18:54 -04:00
}
2021-11-22 11:28:30 -05:00
# Private Routes
##############################
struct RouteHopData {
nonce @0 :Nonce; # nonce for encrypted blob
blob @1 :Data; # encrypted blob with ENC(nonce,DH(PK,SK))
2022-10-29 22:15:50 -04:00
# if this is a safety route RouteHopData, there is a single byte tag appended to the end of the encrypted blob
# it can be one of:
# if more hops remain in this route: RouteHop (0 byte appended as tag)
# if end of safety route and starting private route: PrivateRoute (1 byte appended as tag)
# if this is a private route RouteHopData, only can decode to RouteHop, no tag is appended
2021-11-22 11:28:30 -05:00
}
struct RouteHop {
2022-10-09 22:07:15 -04:00
node :union {
nodeId @0 :NodeID; # node id only for established routes
peerInfo @1 :PeerInfo; # full peer info for this hop to establish the route
}
2022-10-29 22:15:50 -04:00
nextHop @2 :RouteHopData; # Optional: if the private route is a stub, it contains no route hop data, just the target node for the routed operation.
# if this is a safety route routehop, this field is not optional and must exist
2021-11-22 11:28:30 -05:00
}
struct PrivateRoute {
publicKey @0 :RoutePublicKey; # private route public key (unique per private route)
2022-10-28 22:26:21 -04:00
hopCount @1 :UInt8; # Count of hops left in the private route (for timeout calculation purposes only)
firstHop @2 :RouteHop; # Optional: first hop in the private route, if empty, this is the last hop and payload should be decrypted and processed.
2022-10-29 22:15:50 -04:00
}
2021-11-22 11:28:30 -05:00
struct SafetyRoute {
publicKey @0 :RoutePublicKey; # safety route public key (unique per safety route)
2022-10-28 22:26:21 -04:00
hopCount @1 :UInt8; # Count of hops left in the safety route (for timeout calculation purposes only)
2021-11-22 11:28:30 -05:00
hops :union {
data @2 :RouteHopData; # safety route has more hops
private @3 :PrivateRoute; # safety route has ended and private route follows
}
}
# Values
##############################
using ValueSeqNum = UInt32; # sequence numbers for values
struct ValueKey {
publicKey @0 :ValueID; # the location of the value
subkey @1 :Text; # the name of the subkey (or empty if the whole key)
}
2022-07-03 15:52:27 -04:00
# struct ValueKeySeq {
# key @0 :ValueKey; # the location of the value
# seq @1 :ValueSeqNum; # the sequence number of the value subkey
# }
2021-11-22 11:28:30 -05:00
struct ValueData {
2022-11-09 17:11:35 -05:00
data @0 :Data; # value or subvalue contents
2021-11-22 11:28:30 -05:00
seq @1 :ValueSeqNum; # sequence number of value
}
# Operations
##############################
enum NetworkClass {
2022-11-09 17:11:35 -05:00
invalid @0; # X = Invalid network class, network is not yet set up
inboundCapable @1; # I = Inbound capable without relay, may require signal
outboundOnly @2; # O = Outbound only, inbound relay required except with reverse connect signal
webApp @3; # W = PWA, outbound relay is required in most cases
}
enum DialInfoClass {
direct @0; # D = Directly reachable with public IP and no firewall, with statically configured port
mapped @1; # M = Directly reachable with via portmap behind any NAT or firewalled with dynamically negotiated port
fullConeNAT @2; # F = Directly reachable device without portmap behind full-cone NAT
blocked @3; # B = Inbound blocked at firewall but may hole punch with public address
addressRestrictedNAT @4; # A = Device without portmap behind address-only restricted NAT
portRestrictedNAT @5; # P = Device without portmap behind address-and-port restricted NAT
}
struct DialInfoDetail {
2022-04-24 20:16:13 -04:00
dialInfo @0 :DialInfo;
class @1 :DialInfoClass;
2021-11-22 11:28:30 -05:00
}
2022-09-03 13:57:25 -04:00
struct PublicInternetNodeStatus {
2022-04-08 10:17:09 -04:00
willRoute @0 :Bool;
willTunnel @1 :Bool;
willSignal @2 :Bool;
willRelay @3 :Bool;
willValidateDialInfo @4 :Bool;
}
2022-09-03 13:57:25 -04:00
struct LocalNetworkNodeStatus {
willRelay @0 :Bool;
willValidateDialInfo @1 :Bool;
}
struct NodeStatus {
union {
publicInternet @0 :PublicInternetNodeStatus;
localNetwork @1 :LocalNetworkNodeStatus;
}
}
2022-08-01 21:06:31 -04:00
struct ProtocolTypeSet {
2022-04-16 11:18:54 -04:00
udp @0 :Bool;
tcp @1 :Bool;
ws @2 :Bool;
wss @3 :Bool;
}
2022-08-01 21:06:31 -04:00
struct AddressTypeSet {
ipv4 @0 :Bool;
ipv6 @1 :Bool;
}
2022-11-09 17:11:35 -05:00
struct SenderInfo {
socketAddress @0 :SocketAddress; # socket address that for the sending peer
}
2021-11-22 11:28:30 -05:00
struct NodeInfo {
2022-04-08 10:17:09 -04:00
networkClass @0 :NetworkClass; # network class of this node
2022-08-31 21:41:48 -04:00
outboundProtocols @1 :ProtocolTypeSet; # protocols that can go outbound
2022-08-01 21:06:31 -04:00
addressTypes @2 :AddressTypeSet; # address types supported
minVersion @3 :UInt8; # minimum protocol version for rpc
maxVersion @4 :UInt8; # maximum protocol version for rpc
dialInfoDetailList @5 :List(DialInfoDetail); # inbound dial info details for this node
2021-11-22 11:28:30 -05:00
}
2022-11-09 17:11:35 -05:00
struct SignedDirectNodeInfo {
2022-05-10 21:49:42 -04:00
nodeInfo @0 :NodeInfo; # node info
2022-11-09 17:11:35 -05:00
timestamp @1 :UInt64; # when signed node info was generated
signature @2 :Signature; # signature
2022-05-10 21:49:42 -04:00
}
2022-11-09 17:11:35 -05:00
struct SignedRelayedNodeInfo {
nodeInfo @0 :NodeInfo; # node info
relayId @1 :NodeID; # node id for relay
relayInfo @2 :SignedDirectNodeInfo; # signed node info for relay
timestamp @3 :UInt64; # when signed node info was generated
signature @4 :Signature; # signature
}
struct SignedNodeInfo {
union {
direct @0 :SignedDirectNodeInfo; # node info for nodes reachable without a relay
relayed @1 :SignedRelayedNodeInfo; # node info for nodes requiring a relay
}
2021-11-22 11:28:30 -05:00
}
2022-09-03 13:57:25 -04:00
struct PeerInfo {
nodeId @0 :NodeID; # node id for 'closer peer'
signedNodeInfo @1 :SignedNodeInfo; # signed node info for 'closer peer'
}
struct RoutedOperation {
2022-10-30 19:29:31 -04:00
version @0 :UInt8; # crypto version in use for the data
signatures @1 :List(Signature); # signatures from nodes that have handled the private route
nonce @2 :Nonce; # nonce Xmsg
data @3 :Data; # operation encrypted with ENC(Xmsg,DH(PKapr,SKbsr))
2022-09-03 13:57:25 -04:00
}
struct OperationStatusQ {
2022-11-02 15:36:01 -04:00
nodeStatus @0 :NodeStatus; # Optional: node status update about the statusq sender
2022-09-03 13:57:25 -04:00
}
2022-05-10 21:49:42 -04:00
struct OperationStatusA {
2022-11-02 15:36:01 -04:00
nodeStatus @0 :NodeStatus; # Optional: returned node status
senderInfo @1 :SenderInfo; # Optional: info about StatusQ sender from the perspective of the replier
2021-11-22 11:28:30 -05:00
}
struct OperationValidateDialInfo {
dialInfo @0 :DialInfo; # dial info to use for the receipt
2022-05-28 16:11:50 -04:00
receipt @1 :Data; # receipt to return to dial info to prove it is reachable
redirect @2 :Bool; # request a different node do the validate
2021-11-22 11:28:30 -05:00
}
struct OperationReturnReceipt {
2022-05-28 16:11:50 -04:00
receipt @0 :Data; # receipt being returned to its origin
2021-11-22 11:28:30 -05:00
}
struct OperationFindNodeQ {
nodeId @0 :NodeID; # node id to locate
}
struct OperationFindNodeA {
peers @0 :List(PeerInfo); # returned 'closer peer' information
}
struct OperationRoute {
safetyRoute @0 :SafetyRoute; # Where this should go
operation @1 :RoutedOperation; # The operation to be routed
}
2022-05-10 21:49:42 -04:00
struct OperationNodeInfoUpdate {
signedNodeInfo @0 :SignedNodeInfo; # Our signed node info
}
struct OperationAppCallQ {
message @0 :Data; # Opaque request to application
}
struct OperationAppCallA {
message @0 :Data; # Opaque response from application
}
struct OperationAppMessage {
message @0 :Data; # Opaque message to application
}
2021-11-22 11:28:30 -05:00
struct OperationGetValueQ {
key @0 :ValueKey; # key for value to get
}
struct OperationGetValueA {
union {
data @0 :ValueData; # the value if successful
peers @1 :List(PeerInfo); # returned 'closer peer' information if not successful
}
}
struct OperationSetValueQ {
key @0 :ValueKey; # key for value to update
2022-11-09 17:11:35 -05:00
value @1 :ValueData; # value or subvalue contents (older or equal seq number gets dropped)
2021-11-22 11:28:30 -05:00
}
struct OperationSetValueA {
union {
data @0 :ValueData; # the new value if successful, may be a different value than what was set if the seq number was lower or equal
peers @1 :List(PeerInfo); # returned 'closer peer' information if not successful
}
}
struct OperationWatchValueQ {
key @0 :ValueKey; # key for value to watch
}
struct OperationWatchValueA {
expiration @0 :UInt64; # timestamp when this watch will expire in usec since epoch (0 if watch failed)
peers @1 :List(PeerInfo); # returned list of other nodes to ask that could propagate watches
}
struct OperationValueChanged {
key @0 :ValueKey; # key for value that changed
2022-11-09 17:11:35 -05:00
value @1 :ValueData; # value or subvalue contents with sequence number
2021-11-22 11:28:30 -05:00
}
struct OperationSupplyBlockQ {
blockId @0 :BlockID; # hash of the block we can supply
}
struct OperationSupplyBlockA {
union {
expiration @0 :UInt64; # when the block supplier entry will need to be refreshed
peers @1 :List(PeerInfo); # returned 'closer peer' information if not successful
}
}
struct OperationFindBlockQ {
2022-07-03 17:47:46 -04:00
blockId @0 :BlockID; # hash of the block to locate
2021-11-22 11:28:30 -05:00
}
struct OperationFindBlockA {
data @0 :Data; # Optional: the actual block data if we have that block ourselves
# null if we don't have a block to return
suppliers @1 :List(PeerInfo); # returned list of suppliers if we have them
peers @2 :List(PeerInfo); # returned 'closer peer' information
}
2022-04-16 11:18:54 -04:00
struct OperationSignal {
union {
holePunch @0 :SignalInfoHolePunch;
reverseConnect @1 :SignalInfoReverseConnect;
}
2021-11-22 11:28:30 -05:00
}
enum TunnelEndpointMode {
raw @0; # raw tunnel
turn @1; # turn tunnel
}
enum TunnelError {
badId @0; # Tunnel ID was rejected
noEndpoint @1; # Endpoint was unreachable
rejectedMode @2; # Endpoint couldn't provide mode
noCapacity @3; # Endpoint is full
}
struct TunnelEndpoint {
2022-04-16 11:18:54 -04:00
mode @0 :TunnelEndpointMode; # what kind of endpoint this is
2022-07-03 23:20:30 -04:00
description @1 :Text; # endpoint description (TODO)
2021-11-22 11:28:30 -05:00
}
struct FullTunnel {
id @0 :TunnelID; # tunnel id to use everywhere
timeout @1 :UInt64; # duration from last data when this expires if no data is sent or received
local @2 :TunnelEndpoint; # local endpoint
remote @3 :TunnelEndpoint; # remote endpoint
}
struct PartialTunnel {
id @0 :TunnelID; # tunnel id to use everywhere
timeout @1 :UInt64; # timestamp when this expires if not completed
local @2 :TunnelEndpoint; # local endpoint
}
struct OperationStartTunnelQ {
id @0 :TunnelID; # tunnel id to use everywhere
localMode @1 :TunnelEndpointMode; # what kind of local endpoint mode is being requested
depth @2 :UInt8; # the number of nodes in the tunnel
}
struct OperationStartTunnelA {
union {
partial @0 :PartialTunnel; # the first half of the tunnel
error @1 :TunnelError; # if we didn't start the tunnel, why not
}
}
struct OperationCompleteTunnelQ {
id @0 :TunnelID; # tunnel id to use everywhere
localMode @1 :TunnelEndpointMode; # what kind of local endpoint mode is being requested
depth @2 :UInt8; # the number of nodes in the tunnel
endpoint @3 :TunnelEndpoint; # the remote endpoint to complete
}
struct OperationCompleteTunnelA {
union {
tunnel @0 :FullTunnel; # the tunnel description
error @1 :TunnelError; # if we didn't complete the tunnel, why not
}
}
struct OperationCancelTunnelQ {
2022-07-03 23:20:30 -04:00
id @0 :TunnelID; # the tunnel id to cancel
2021-11-22 11:28:30 -05:00
}
struct OperationCancelTunnelA {
union {
tunnel @0 :TunnelID; # the tunnel id that was cancelled
error @1 :TunnelError; # if we couldn't cancel, why not
}
}
2022-07-03 23:20:30 -04:00
# Things that want an answer
struct Question {
2021-11-22 11:28:30 -05:00
respondTo :union {
2022-09-03 13:57:25 -04:00
sender @0 :Void; # sender
privateRoute @1 :PrivateRoute; # embedded private route to be used for reply
2022-07-03 23:20:30 -04:00
}
detail :union {
# Direct operations
2022-09-03 13:57:25 -04:00
statusQ @2 :OperationStatusQ;
findNodeQ @3 :OperationFindNodeQ;
2022-07-03 23:20:30 -04:00
# Routable operations
2022-09-03 13:57:25 -04:00
getValueQ @4 :OperationGetValueQ;
setValueQ @5 :OperationSetValueQ;
watchValueQ @6 :OperationWatchValueQ;
supplyBlockQ @7 :OperationSupplyBlockQ;
findBlockQ @8 :OperationFindBlockQ;
appCallQ @9 :OperationAppCallQ;
2022-07-03 23:20:30 -04:00
# Tunnel operations
startTunnelQ @10 :OperationStartTunnelQ;
completeTunnelQ @11 :OperationCompleteTunnelQ;
cancelTunnelQ @12 :OperationCancelTunnelQ;
2022-07-03 23:20:30 -04:00
}
}
2021-11-22 11:28:30 -05:00
2022-07-03 23:20:30 -04:00
# Things that don't want an answer
struct Statement {
2021-11-22 11:28:30 -05:00
detail :union {
# Direct operations
2022-07-03 23:20:30 -04:00
validateDialInfo @0 :OperationValidateDialInfo;
route @1 :OperationRoute;
nodeInfoUpdate @2 :OperationNodeInfoUpdate;
2021-11-22 11:28:30 -05:00
# Routable operations
2022-07-03 23:20:30 -04:00
valueChanged @3 :OperationValueChanged;
signal @4 :OperationSignal;
returnReceipt @5 :OperationReturnReceipt;
appMessage @6 :OperationAppMessage;
2022-07-03 23:20:30 -04:00
}
}
# Things that are answers
struct Answer {
detail :union {
# Direct operations
statusA @0 :OperationStatusA;
findNodeA @1 :OperationFindNodeA;
2021-11-22 11:28:30 -05:00
2022-07-03 23:20:30 -04:00
# Routable operations
getValueA @2 :OperationGetValueA;
setValueA @3 :OperationSetValueA;
watchValueA @4 :OperationWatchValueA;
supplyBlockA @5 :OperationSupplyBlockA;
findBlockA @6 :OperationFindBlockA;
appCallA @7 :OperationAppCallA;
2021-11-22 11:28:30 -05:00
# Tunnel operations
startTunnelA @8 :OperationStartTunnelA;
completeTunnelA @9 :OperationCompleteTunnelA;
cancelTunnelA @10 :OperationCancelTunnelA;
2022-07-03 23:20:30 -04:00
}
}
struct Operation {
opId @0 :UInt64; # Random RPC ID. Must be random to foil reply forgery attacks.
2022-09-04 14:17:28 -04:00
senderNodeInfo @1 :SignedNodeInfo; # (optional) SignedNodeInfo for the sender to be cached by the receiver.
2022-07-03 23:20:30 -04:00
kind :union {
2022-09-03 13:57:25 -04:00
question @2 :Question;
statement @3 :Statement;
answer @4 :Answer;
2021-11-22 11:28:30 -05:00
}
}