From a04f315b0ea0d99f188792fcda4b1275c23193c7 Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Fri, 7 Feb 2025 09:59:40 +0100 Subject: [PATCH 1/2] Updating grpc --- go.mod | 7 ++++--- go.sum | 9 ++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 05dbf662..1843f265 100644 --- a/go.mod +++ b/go.mod @@ -22,11 +22,13 @@ require ( golang.org/x/tools v0.28.0 golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 google.golang.org/grpc v1.70.0 - google.golang.org/protobuf v1.36.4 gopkg.in/yaml.v2 v2.4.0 ) -require github.com/golang/protobuf v1.5.4 // indirect +require ( + google.golang.org/genproto/googleapis/rpc v0.0.0-20250204164813-702378808489 // indirect + google.golang.org/protobuf v1.36.5 // indirect +) require ( github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect @@ -131,7 +133,6 @@ require ( golang.org/x/sync v0.10.0 // indirect golang.org/x/sys v0.29.0 // indirect golang.org/x/text v0.21.0 // indirect - google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.3.0 // indirect ) diff --git a/go.sum b/go.sum index ec745f83..1fe06f46 100644 --- a/go.sum +++ b/go.sum @@ -87,7 +87,6 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -602,16 +601,16 @@ google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoA google.golang.org/genproto v0.0.0-20181029155118-b69ba1387ce2/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20181202183823-bd91e49a0898/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg= google.golang.org/genproto v0.0.0-20190306203927-b5d61aea6440/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250204164813-702378808489 h1:5bKytslY8ViY0Cj/ewmRtrWHW64bNF03cAatUUFCdFI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250204164813-702378808489/go.mod h1:8BS3B93F/U1juMFq9+EDk+qOT5CO1R9IzXxG3PTqiRk= google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ= google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw= -google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM= -google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= +google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 61f210e90f625f0b4126faaf1d75036ecf4182e0 Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Fri, 7 Feb 2025 15:41:39 +0100 Subject: [PATCH 2/2] Adding proto-files and fixing private method --- devbox.json | 19 + devbox.lock | 281 ++++++++++++++ go.mod | 6 +- mino/minogrpc/ptypes/mod.go | 5 +- mino/minogrpc/ptypes/overlay.pb.go | 472 ++++++++++++++++++++++++ mino/minogrpc/ptypes/overlay.proto | 3 +- mino/minogrpc/ptypes/overlay_grpc.pb.go | 288 +++++++++++++++ mino/minogrpc/server.go | 1 + mino/minows/controller/controller.go | 2 +- mino/minows/minows.go | 2 +- mino/minows/minows_test.go | 10 +- 11 files changed, 1076 insertions(+), 13 deletions(-) create mode 100644 devbox.json create mode 100644 devbox.lock create mode 100644 mino/minogrpc/ptypes/overlay.pb.go create mode 100644 mino/minogrpc/ptypes/overlay_grpc.pb.go diff --git a/devbox.json b/devbox.json new file mode 100644 index 00000000..9a1f84b3 --- /dev/null +++ b/devbox.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.13.7/.schema/devbox.schema.json", + "packages": [ + "go@latest", + "protoc-gen-go@latest", + "protoc-gen-go-grpc@latest", + "darwin.apple_sdk.frameworks.Security" + ], + "shell": { + "init_hook": [ + "echo 'Welcome to devbox!' > /dev/null" + ], + "scripts": { + "test": [ + "echo \"Error: no test specified\" && exit 1" + ] + } + } +} diff --git a/devbox.lock b/devbox.lock new file mode 100644 index 00000000..87b60329 --- /dev/null +++ b/devbox.lock @@ -0,0 +1,281 @@ +{ + "lockfile_version": "1", + "packages": { + "darwin.apple_sdk.frameworks.Security": { + "resolved": "github:NixOS/nixpkgs/75a52265bda7fd25e06e3a67dee3f0354e73243c#darwin.apple_sdk.frameworks.Security", + "source": "nixpkg" + }, + "go@latest": { + "last_modified": "2025-01-19T08:16:51Z", + "resolved": "github:NixOS/nixpkgs/50165c4f7eb48ce82bd063e1fb8047a0f515f8ce#go", + "source": "devbox-search", + "version": "1.23.4", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/lg7l1czmd5hqwwhjszprdz342q98zmkw-go-1.23.4", + "default": true + } + ], + "store_path": "/nix/store/lg7l1czmd5hqwwhjszprdz342q98zmkw-go-1.23.4" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/2x7k6yj9z37s3d3x5j3kkz6bcak8k9qr-go-1.23.4", + "default": true + } + ], + "store_path": "/nix/store/2x7k6yj9z37s3d3x5j3kkz6bcak8k9qr-go-1.23.4" + }, + "x86_64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/8x0ag0v37rfy9z58a8yy3hakj3dzdr9c-go-1.23.4", + "default": true + } + ], + "store_path": "/nix/store/8x0ag0v37rfy9z58a8yy3hakj3dzdr9c-go-1.23.4" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4", + "default": true + } + ], + "store_path": "/nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4" + } + } + }, + "protobuf@latest": { + "last_modified": "2025-01-19T08:16:51Z", + "resolved": "github:NixOS/nixpkgs/50165c4f7eb48ce82bd063e1fb8047a0f515f8ce#protobuf", + "source": "devbox-search", + "version": "29.2", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/rf1k2r8bh34i23za7w9g5nf459sldbb5-protobuf-29.2", + "default": true + } + ], + "store_path": "/nix/store/rf1k2r8bh34i23za7w9g5nf459sldbb5-protobuf-29.2" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/b0lnp9h1i5jv43nw1qyvb8xdyck3x2v2-protobuf-29.2", + "default": true + } + ], + "store_path": "/nix/store/b0lnp9h1i5jv43nw1qyvb8xdyck3x2v2-protobuf-29.2" + }, + "x86_64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/c97xv0vszx2g81d9339ndqf72z3ji6hy-protobuf-29.2", + "default": true + } + ], + "store_path": "/nix/store/c97xv0vszx2g81d9339ndqf72z3ji6hy-protobuf-29.2" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/r4k147v919pir4fj74in3axcbma03793-protobuf-29.2", + "default": true + } + ], + "store_path": "/nix/store/r4k147v919pir4fj74in3axcbma03793-protobuf-29.2" + } + } + }, + "protobufc@latest": { + "last_modified": "2025-02-04T21:04:56Z", + "resolved": "github:NixOS/nixpkgs/f7384aacd0ecd28681a99269ac0dff2c3a805d63#protobufc", + "source": "devbox-search", + "version": "1.5.0", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/5in1i1i2dfkld4r6swfz6c6mqnd8wrxg-protobuf-c-1.5.0", + "default": true + }, + { + "name": "dev", + "path": "/nix/store/4bf4vq2kivja810ha3zh11lal2acrrjy-protobuf-c-1.5.0-dev" + }, + { + "name": "lib", + "path": "/nix/store/dqi5wlpmsyypmpz7a1kkr9w26pxswv4i-protobuf-c-1.5.0-lib" + } + ], + "store_path": "/nix/store/5in1i1i2dfkld4r6swfz6c6mqnd8wrxg-protobuf-c-1.5.0" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/cqkw54pqkc8jjpbz1r30f48s5j1y7s1g-protobuf-c-1.5.0", + "default": true + }, + { + "name": "dev", + "path": "/nix/store/yhsq4ppdji6pk1l37kgfymkq5w6m7fna-protobuf-c-1.5.0-dev" + }, + { + "name": "lib", + "path": "/nix/store/9argv2dc81lf9z5jcvv2n071y553d03d-protobuf-c-1.5.0-lib" + } + ], + "store_path": "/nix/store/cqkw54pqkc8jjpbz1r30f48s5j1y7s1g-protobuf-c-1.5.0" + }, + "x86_64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/nvwl5ql2s8awykv3ksipacxda3qwm545-protobuf-c-1.5.0", + "default": true + }, + { + "name": "lib", + "path": "/nix/store/bgzih0sd5gv3d903dn0g75bnhlabzsyn-protobuf-c-1.5.0-lib" + }, + { + "name": "dev", + "path": "/nix/store/wrmx3v7v25x9rl90x1wfgckggbxdn3r0-protobuf-c-1.5.0-dev" + } + ], + "store_path": "/nix/store/nvwl5ql2s8awykv3ksipacxda3qwm545-protobuf-c-1.5.0" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/mgijy78pqyd5z678a2afkifgynh0kv7i-protobuf-c-1.5.0", + "default": true + }, + { + "name": "dev", + "path": "/nix/store/g5gxq59smnzd7sd10n16ydvhfkwk7a3n-protobuf-c-1.5.0-dev" + }, + { + "name": "lib", + "path": "/nix/store/27x0za8p5amz78hp7rixwy4z15rzmn37-protobuf-c-1.5.0-lib" + } + ], + "store_path": "/nix/store/mgijy78pqyd5z678a2afkifgynh0kv7i-protobuf-c-1.5.0" + } + } + }, + "protoc-gen-go-grpc@latest": { + "last_modified": "2025-01-19T08:16:51Z", + "resolved": "github:NixOS/nixpkgs/50165c4f7eb48ce82bd063e1fb8047a0f515f8ce#protoc-gen-go-grpc", + "source": "devbox-search", + "version": "1.5.1", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/7k4630z43r5djk6r0y3g7z2jynxr1qwl-protoc-gen-go-grpc-1.5.1", + "default": true + } + ], + "store_path": "/nix/store/7k4630z43r5djk6r0y3g7z2jynxr1qwl-protoc-gen-go-grpc-1.5.1" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/8fkxgyd2v5b6amnzwpvmc7ab7jqgmq0i-protoc-gen-go-grpc-1.5.1", + "default": true + } + ], + "store_path": "/nix/store/8fkxgyd2v5b6amnzwpvmc7ab7jqgmq0i-protoc-gen-go-grpc-1.5.1" + }, + "x86_64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/4wk8sl6pbr0app5aldxxip1n5c1fw09l-protoc-gen-go-grpc-1.5.1", + "default": true + } + ], + "store_path": "/nix/store/4wk8sl6pbr0app5aldxxip1n5c1fw09l-protoc-gen-go-grpc-1.5.1" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/v9jjl5hhgr5qbyglrl4wksxckfaf8s3n-protoc-gen-go-grpc-1.5.1", + "default": true + } + ], + "store_path": "/nix/store/v9jjl5hhgr5qbyglrl4wksxckfaf8s3n-protoc-gen-go-grpc-1.5.1" + } + } + }, + "protoc-gen-go@latest": { + "last_modified": "2025-02-01T06:33:04Z", + "resolved": "github:NixOS/nixpkgs/047ebac174c408d6e5428b1865478893001276c5#protoc-gen-go", + "source": "devbox-search", + "version": "1.36.4", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/ql08hq2d7havw1mmmw7xa23immnvxqlm-protoc-gen-go-1.36.4", + "default": true + } + ], + "store_path": "/nix/store/ql08hq2d7havw1mmmw7xa23immnvxqlm-protoc-gen-go-1.36.4" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/7hlsmkm0f5jiw767awgf2q6na92isryx-protoc-gen-go-1.36.4", + "default": true + } + ], + "store_path": "/nix/store/7hlsmkm0f5jiw767awgf2q6na92isryx-protoc-gen-go-1.36.4" + }, + "x86_64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/1fp5af5bvv9idqrv3cvfn851vy2rkmpf-protoc-gen-go-1.36.4", + "default": true + } + ], + "store_path": "/nix/store/1fp5af5bvv9idqrv3cvfn851vy2rkmpf-protoc-gen-go-1.36.4" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/qlamadsx2x0f999c20y3jgkqvwa8ry9r-protoc-gen-go-1.36.4", + "default": true + } + ], + "store_path": "/nix/store/qlamadsx2x0f999c20y3jgkqvwa8ry9r-protoc-gen-go-1.36.4" + } + } + } + } +} diff --git a/go.mod b/go.mod index 1843f265..b6c00542 100644 --- a/go.mod +++ b/go.mod @@ -22,13 +22,11 @@ require ( golang.org/x/tools v0.28.0 golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 google.golang.org/grpc v1.70.0 + google.golang.org/protobuf v1.36.5 gopkg.in/yaml.v2 v2.4.0 ) -require ( - google.golang.org/genproto/googleapis/rpc v0.0.0-20250204164813-702378808489 // indirect - google.golang.org/protobuf v1.36.5 // indirect -) +require google.golang.org/genproto/googleapis/rpc v0.0.0-20250204164813-702378808489 // indirect require ( github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect diff --git a/mino/minogrpc/ptypes/mod.go b/mino/minogrpc/ptypes/mod.go index f515b6ff..8a51f842 100644 --- a/mino/minogrpc/ptypes/mod.go +++ b/mino/minogrpc/ptypes/mod.go @@ -1,5 +1,8 @@ // Package ptypes contains the protobuf definitions for the implementation of // minogrpc. +// To re-generate, install protoc and then run +// +// go generate . package ptypes -//go:generate protoc -I ./ --go_out=plugins=grpc:./ ./overlay.proto +//go:generate protoc -I ./ --go_out=./ --go-grpc_out=./ ./overlay.proto diff --git a/mino/minogrpc/ptypes/overlay.pb.go b/mino/minogrpc/ptypes/overlay.pb.go new file mode 100644 index 00000000..fcfeae4a --- /dev/null +++ b/mino/minogrpc/ptypes/overlay.pb.go @@ -0,0 +1,472 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.4 +// protoc v5.29.2 +// source: overlay.proto + +package ptypes + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// CertificateChain is a wrapper around a chain of x509 raw certificates and its +// address. +type CertificateChain struct { + state protoimpl.MessageState `protogen:"open.v1"` + Address []byte `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // value represents certificates as ASN.1 DER data. The certificates must be + // concatenated with no intermediate padding. This value can be parsed with + // `x509.LoadCertificates`. + Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *CertificateChain) Reset() { + *x = CertificateChain{} + mi := &file_overlay_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CertificateChain) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CertificateChain) ProtoMessage() {} + +func (x *CertificateChain) ProtoReflect() protoreflect.Message { + mi := &file_overlay_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CertificateChain.ProtoReflect.Descriptor instead. +func (*CertificateChain) Descriptor() ([]byte, []int) { + return file_overlay_proto_rawDescGZIP(), []int{0} +} + +func (x *CertificateChain) GetAddress() []byte { + if x != nil { + return x.Address + } + return nil +} + +func (x *CertificateChain) GetValue() []byte { + if x != nil { + return x.Value + } + return nil +} + +type CertificateAck struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *CertificateAck) Reset() { + *x = CertificateAck{} + mi := &file_overlay_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CertificateAck) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CertificateAck) ProtoMessage() {} + +func (x *CertificateAck) ProtoReflect() protoreflect.Message { + mi := &file_overlay_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CertificateAck.ProtoReflect.Descriptor instead. +func (*CertificateAck) Descriptor() ([]byte, []int) { + return file_overlay_proto_rawDescGZIP(), []int{1} +} + +// JoinRequest sends a request to join a network to a distant node. It must +// contain a valid token and its own certificate. +type JoinRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + Chain *CertificateChain `protobuf:"bytes,2,opt,name=chain,proto3" json:"chain,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *JoinRequest) Reset() { + *x = JoinRequest{} + mi := &file_overlay_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *JoinRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*JoinRequest) ProtoMessage() {} + +func (x *JoinRequest) ProtoReflect() protoreflect.Message { + mi := &file_overlay_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use JoinRequest.ProtoReflect.Descriptor instead. +func (*JoinRequest) Descriptor() ([]byte, []int) { + return file_overlay_proto_rawDescGZIP(), []int{2} +} + +func (x *JoinRequest) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *JoinRequest) GetChain() *CertificateChain { + if x != nil { + return x.Chain + } + return nil +} + +// JoinResponse is a response of a join request that contains the list of +// certificates known by the distant node. +type JoinResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Peers []*CertificateChain `protobuf:"bytes,1,rep,name=peers,proto3" json:"peers,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *JoinResponse) Reset() { + *x = JoinResponse{} + mi := &file_overlay_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *JoinResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*JoinResponse) ProtoMessage() {} + +func (x *JoinResponse) ProtoReflect() protoreflect.Message { + mi := &file_overlay_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use JoinResponse.ProtoReflect.Descriptor instead. +func (*JoinResponse) Descriptor() ([]byte, []int) { + return file_overlay_proto_rawDescGZIP(), []int{3} +} + +func (x *JoinResponse) GetPeers() []*CertificateChain { + if x != nil { + return x.Peers + } + return nil +} + +// Message is a network message that contains the address of the sender and the +// payload. +type Message struct { + state protoimpl.MessageState `protogen:"open.v1"` + From []byte `protobuf:"bytes,1,opt,name=from,proto3" json:"from,omitempty"` + Payload []byte `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Message) Reset() { + *x = Message{} + mi := &file_overlay_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Message) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Message) ProtoMessage() {} + +func (x *Message) ProtoReflect() protoreflect.Message { + mi := &file_overlay_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Message.ProtoReflect.Descriptor instead. +func (*Message) Descriptor() ([]byte, []int) { + return file_overlay_proto_rawDescGZIP(), []int{4} +} + +func (x *Message) GetFrom() []byte { + if x != nil { + return x.From + } + return nil +} + +func (x *Message) GetPayload() []byte { + if x != nil { + return x.Payload + } + return nil +} + +// Packet is a wrapper around a packet. +type Packet struct { + state protoimpl.MessageState `protogen:"open.v1"` + Serialized []byte `protobuf:"bytes,1,opt,name=serialized,proto3" json:"serialized,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Packet) Reset() { + *x = Packet{} + mi := &file_overlay_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Packet) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Packet) ProtoMessage() {} + +func (x *Packet) ProtoReflect() protoreflect.Message { + mi := &file_overlay_proto_msgTypes[5] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Packet.ProtoReflect.Descriptor instead. +func (*Packet) Descriptor() ([]byte, []int) { + return file_overlay_proto_rawDescGZIP(), []int{5} +} + +func (x *Packet) GetSerialized() []byte { + if x != nil { + return x.Serialized + } + return nil +} + +// Ack is the return of a unicast request to forward a message. +type Ack struct { + state protoimpl.MessageState `protogen:"open.v1"` + Errors []string `protobuf:"bytes,1,rep,name=errors,proto3" json:"errors,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Ack) Reset() { + *x = Ack{} + mi := &file_overlay_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Ack) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Ack) ProtoMessage() {} + +func (x *Ack) ProtoReflect() protoreflect.Message { + mi := &file_overlay_proto_msgTypes[6] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Ack.ProtoReflect.Descriptor instead. +func (*Ack) Descriptor() ([]byte, []int) { + return file_overlay_proto_rawDescGZIP(), []int{6} +} + +func (x *Ack) GetErrors() []string { + if x != nil { + return x.Errors + } + return nil +} + +var File_overlay_proto protoreflect.FileDescriptor + +var file_overlay_proto_rawDesc = string([]byte{ + 0x0a, 0x0d, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x06, 0x70, 0x74, 0x79, 0x70, 0x65, 0x73, 0x22, 0x42, 0x0a, 0x10, 0x43, 0x65, 0x72, 0x74, 0x69, + 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x61, + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x61, 0x64, + 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x10, 0x0a, 0x0e, 0x43, + 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x41, 0x63, 0x6b, 0x22, 0x53, 0x0a, + 0x0b, 0x4a, 0x6f, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, + 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x12, 0x2e, 0x0a, 0x05, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x43, 0x65, 0x72, 0x74, 0x69, + 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x52, 0x05, 0x63, 0x68, 0x61, + 0x69, 0x6e, 0x22, 0x3e, 0x0a, 0x0c, 0x4a, 0x6f, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x2e, 0x0a, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x43, 0x65, 0x72, 0x74, 0x69, + 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x52, 0x05, 0x70, 0x65, 0x65, + 0x72, 0x73, 0x22, 0x37, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, + 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x66, 0x72, 0x6f, + 0x6d, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x28, 0x0a, 0x06, 0x50, + 0x61, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, + 0x7a, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x69, 0x61, + 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x22, 0x1d, 0x0a, 0x03, 0x41, 0x63, 0x6b, 0x12, 0x16, 0x0a, 0x06, + 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, + 0x72, 0x6f, 0x72, 0x73, 0x32, 0x81, 0x02, 0x0a, 0x07, 0x4f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, + 0x12, 0x33, 0x0a, 0x04, 0x4a, 0x6f, 0x69, 0x6e, 0x12, 0x13, 0x2e, 0x70, 0x74, 0x79, 0x70, 0x65, + 0x73, 0x2e, 0x4a, 0x6f, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, + 0x70, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x4a, 0x6f, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3b, 0x0a, 0x05, 0x53, 0x68, 0x61, 0x72, 0x65, 0x12, 0x18, + 0x2e, 0x70, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, + 0x61, 0x74, 0x65, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x1a, 0x16, 0x2e, 0x70, 0x74, 0x79, 0x70, 0x65, + 0x73, 0x2e, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x41, 0x63, 0x6b, + 0x22, 0x00, 0x12, 0x2a, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x0f, 0x2e, 0x70, 0x74, 0x79, + 0x70, 0x65, 0x73, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x0f, 0x2e, 0x70, 0x74, + 0x79, 0x70, 0x65, 0x73, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x00, 0x12, 0x2e, + 0x0a, 0x06, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x0e, 0x2e, 0x70, 0x74, 0x79, 0x70, 0x65, + 0x73, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x1a, 0x0e, 0x2e, 0x70, 0x74, 0x79, 0x70, 0x65, + 0x73, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x12, 0x28, + 0x0a, 0x07, 0x46, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x12, 0x0e, 0x2e, 0x70, 0x74, 0x79, 0x70, + 0x65, 0x73, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x1a, 0x0b, 0x2e, 0x70, 0x74, 0x79, 0x70, + 0x65, 0x73, 0x2e, 0x41, 0x63, 0x6b, 0x22, 0x00, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x3b, 0x70, 0x74, + 0x79, 0x70, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +}) + +var ( + file_overlay_proto_rawDescOnce sync.Once + file_overlay_proto_rawDescData []byte +) + +func file_overlay_proto_rawDescGZIP() []byte { + file_overlay_proto_rawDescOnce.Do(func() { + file_overlay_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_overlay_proto_rawDesc), len(file_overlay_proto_rawDesc))) + }) + return file_overlay_proto_rawDescData +} + +var file_overlay_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_overlay_proto_goTypes = []any{ + (*CertificateChain)(nil), // 0: ptypes.CertificateChain + (*CertificateAck)(nil), // 1: ptypes.CertificateAck + (*JoinRequest)(nil), // 2: ptypes.JoinRequest + (*JoinResponse)(nil), // 3: ptypes.JoinResponse + (*Message)(nil), // 4: ptypes.Message + (*Packet)(nil), // 5: ptypes.Packet + (*Ack)(nil), // 6: ptypes.Ack +} +var file_overlay_proto_depIdxs = []int32{ + 0, // 0: ptypes.JoinRequest.chain:type_name -> ptypes.CertificateChain + 0, // 1: ptypes.JoinResponse.peers:type_name -> ptypes.CertificateChain + 2, // 2: ptypes.Overlay.Join:input_type -> ptypes.JoinRequest + 0, // 3: ptypes.Overlay.Share:input_type -> ptypes.CertificateChain + 4, // 4: ptypes.Overlay.Call:input_type -> ptypes.Message + 5, // 5: ptypes.Overlay.Stream:input_type -> ptypes.Packet + 5, // 6: ptypes.Overlay.Forward:input_type -> ptypes.Packet + 3, // 7: ptypes.Overlay.Join:output_type -> ptypes.JoinResponse + 1, // 8: ptypes.Overlay.Share:output_type -> ptypes.CertificateAck + 4, // 9: ptypes.Overlay.Call:output_type -> ptypes.Message + 5, // 10: ptypes.Overlay.Stream:output_type -> ptypes.Packet + 6, // 11: ptypes.Overlay.Forward:output_type -> ptypes.Ack + 7, // [7:12] is the sub-list for method output_type + 2, // [2:7] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_overlay_proto_init() } +func file_overlay_proto_init() { + if File_overlay_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_overlay_proto_rawDesc), len(file_overlay_proto_rawDesc)), + NumEnums: 0, + NumMessages: 7, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_overlay_proto_goTypes, + DependencyIndexes: file_overlay_proto_depIdxs, + MessageInfos: file_overlay_proto_msgTypes, + }.Build() + File_overlay_proto = out.File + file_overlay_proto_goTypes = nil + file_overlay_proto_depIdxs = nil +} diff --git a/mino/minogrpc/ptypes/overlay.proto b/mino/minogrpc/ptypes/overlay.proto index 51d80c04..474de101 100644 --- a/mino/minogrpc/ptypes/overlay.proto +++ b/mino/minogrpc/ptypes/overlay.proto @@ -1,6 +1,7 @@ syntax = "proto3"; -option go_package = "./overlay"; +package ptypes; +option go_package = ".;ptypes"; // CertificateChain is a wrapper around a chain of x509 raw certificates and its // address. diff --git a/mino/minogrpc/ptypes/overlay_grpc.pb.go b/mino/minogrpc/ptypes/overlay_grpc.pb.go new file mode 100644 index 00000000..211bf125 --- /dev/null +++ b/mino/minogrpc/ptypes/overlay_grpc.pb.go @@ -0,0 +1,288 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.29.2 +// source: overlay.proto + +package ptypes + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + Overlay_Join_FullMethodName = "/ptypes.Overlay/Join" + Overlay_Share_FullMethodName = "/ptypes.Overlay/Share" + Overlay_Call_FullMethodName = "/ptypes.Overlay/Call" + Overlay_Stream_FullMethodName = "/ptypes.Overlay/Stream" + Overlay_Forward_FullMethodName = "/ptypes.Overlay/Forward" +) + +// OverlayClient is the client API for Overlay service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type OverlayClient interface { + // Join handles join request from an unknown node. It accepts to share the + // certificates if the token is valid. + Join(ctx context.Context, in *JoinRequest, opts ...grpc.CallOption) (*JoinResponse, error) + // Share handles a certificate share from another participant of the + // network. + Share(ctx context.Context, in *CertificateChain, opts ...grpc.CallOption) (*CertificateAck, error) + // Call is a unicast rpc to send a message to a participant and expect a + // reply from it. + Call(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Message, error) + // Stream is a stream rpc that will build a network of nodes which will + // relay the messages between each others. + Stream(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[Packet, Packet], error) + // Forward is used in association with Stream to send a message through + // relays and get a feedback that the message has been received. + Forward(ctx context.Context, in *Packet, opts ...grpc.CallOption) (*Ack, error) +} + +type overlayClient struct { + cc grpc.ClientConnInterface +} + +func NewOverlayClient(cc grpc.ClientConnInterface) OverlayClient { + return &overlayClient{cc} +} + +func (c *overlayClient) Join(ctx context.Context, in *JoinRequest, opts ...grpc.CallOption) (*JoinResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(JoinResponse) + err := c.cc.Invoke(ctx, Overlay_Join_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *overlayClient) Share(ctx context.Context, in *CertificateChain, opts ...grpc.CallOption) (*CertificateAck, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(CertificateAck) + err := c.cc.Invoke(ctx, Overlay_Share_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *overlayClient) Call(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Message, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Message) + err := c.cc.Invoke(ctx, Overlay_Call_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *overlayClient) Stream(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[Packet, Packet], error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + stream, err := c.cc.NewStream(ctx, &Overlay_ServiceDesc.Streams[0], Overlay_Stream_FullMethodName, cOpts...) + if err != nil { + return nil, err + } + x := &grpc.GenericClientStream[Packet, Packet]{ClientStream: stream} + return x, nil +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Overlay_StreamClient = grpc.BidiStreamingClient[Packet, Packet] + +func (c *overlayClient) Forward(ctx context.Context, in *Packet, opts ...grpc.CallOption) (*Ack, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Ack) + err := c.cc.Invoke(ctx, Overlay_Forward_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// OverlayServer is the server API for Overlay service. +// All implementations must embed UnimplementedOverlayServer +// for forward compatibility. +type OverlayServer interface { + // Join handles join request from an unknown node. It accepts to share the + // certificates if the token is valid. + Join(context.Context, *JoinRequest) (*JoinResponse, error) + // Share handles a certificate share from another participant of the + // network. + Share(context.Context, *CertificateChain) (*CertificateAck, error) + // Call is a unicast rpc to send a message to a participant and expect a + // reply from it. + Call(context.Context, *Message) (*Message, error) + // Stream is a stream rpc that will build a network of nodes which will + // relay the messages between each others. + Stream(grpc.BidiStreamingServer[Packet, Packet]) error + // Forward is used in association with Stream to send a message through + // relays and get a feedback that the message has been received. + Forward(context.Context, *Packet) (*Ack, error) + mustEmbedUnimplementedOverlayServer() +} + +// UnimplementedOverlayServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedOverlayServer struct{} + +func (UnimplementedOverlayServer) Join(context.Context, *JoinRequest) (*JoinResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Join not implemented") +} +func (UnimplementedOverlayServer) Share(context.Context, *CertificateChain) (*CertificateAck, error) { + return nil, status.Errorf(codes.Unimplemented, "method Share not implemented") +} +func (UnimplementedOverlayServer) Call(context.Context, *Message) (*Message, error) { + return nil, status.Errorf(codes.Unimplemented, "method Call not implemented") +} +func (UnimplementedOverlayServer) Stream(grpc.BidiStreamingServer[Packet, Packet]) error { + return status.Errorf(codes.Unimplemented, "method Stream not implemented") +} +func (UnimplementedOverlayServer) Forward(context.Context, *Packet) (*Ack, error) { + return nil, status.Errorf(codes.Unimplemented, "method Forward not implemented") +} +func (UnimplementedOverlayServer) mustEmbedUnimplementedOverlayServer() {} +func (UnimplementedOverlayServer) testEmbeddedByValue() {} + +// UnsafeOverlayServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to OverlayServer will +// result in compilation errors. +type UnsafeOverlayServer interface { + mustEmbedUnimplementedOverlayServer() +} + +func RegisterOverlayServer(s grpc.ServiceRegistrar, srv OverlayServer) { + // If the following call pancis, it indicates UnimplementedOverlayServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&Overlay_ServiceDesc, srv) +} + +func _Overlay_Join_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(JoinRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OverlayServer).Join(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Overlay_Join_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OverlayServer).Join(ctx, req.(*JoinRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Overlay_Share_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CertificateChain) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OverlayServer).Share(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Overlay_Share_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OverlayServer).Share(ctx, req.(*CertificateChain)) + } + return interceptor(ctx, in, info, handler) +} + +func _Overlay_Call_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Message) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OverlayServer).Call(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Overlay_Call_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OverlayServer).Call(ctx, req.(*Message)) + } + return interceptor(ctx, in, info, handler) +} + +func _Overlay_Stream_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(OverlayServer).Stream(&grpc.GenericServerStream[Packet, Packet]{ServerStream: stream}) +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Overlay_StreamServer = grpc.BidiStreamingServer[Packet, Packet] + +func _Overlay_Forward_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Packet) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OverlayServer).Forward(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Overlay_Forward_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OverlayServer).Forward(ctx, req.(*Packet)) + } + return interceptor(ctx, in, info, handler) +} + +// Overlay_ServiceDesc is the grpc.ServiceDesc for Overlay service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Overlay_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "ptypes.Overlay", + HandlerType: (*OverlayServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Join", + Handler: _Overlay_Join_Handler, + }, + { + MethodName: "Share", + Handler: _Overlay_Share_Handler, + }, + { + MethodName: "Call", + Handler: _Overlay_Call_Handler, + }, + { + MethodName: "Forward", + Handler: _Overlay_Forward_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "Stream", + Handler: _Overlay_Stream_Handler, + ServerStreams: true, + ClientStreams: true, + }, + }, + Metadata: "overlay.proto", +} diff --git a/mino/minogrpc/server.go b/mino/minogrpc/server.go index 68c18719..7a91de7b 100644 --- a/mino/minogrpc/server.go +++ b/mino/minogrpc/server.go @@ -58,6 +58,7 @@ const ( var getTracerForAddr = tracing.GetTracerForAddr type overlayServer struct { + ptypes.UnimplementedOverlayServer *overlay endpoints map[string]*Endpoint diff --git a/mino/minows/controller/controller.go b/mino/minows/controller/controller.go index 2c6b9b03..7d1f92e7 100644 --- a/mino/minows/controller/controller.go +++ b/mino/minows/controller/controller.go @@ -132,7 +132,7 @@ func (c controller) OnStop(inj node.Injector) error { if err != nil { return xerrors.Errorf("could not resolve mino: %v", err) } - err = m.stop() + err = m.Stop() if err != nil { return xerrors.Errorf("could not stop mino: %v", err) } diff --git a/mino/minows/minows.go b/mino/minows/minows.go index 55e19490..1924fab3 100644 --- a/mino/minows/minows.go +++ b/mino/minows/minows.go @@ -150,7 +150,7 @@ func (m *Minows) CreateRPC(name string, h mino.Handler, f serde.Factory) (mino.R return r, nil } -func (m *Minows) stop() error { +func (m *Minows) Stop() error { err := m.host.Close() m.manager.remove(m) diff --git a/mino/minows/minows_test.go b/mino/minows/minows_test.go index ee62549c..7c857654 100644 --- a/mino/minows/minows_test.go +++ b/mino/minows/minows_test.go @@ -32,7 +32,7 @@ func TestNewMinows(t *testing.T) { require.NoError(t, err) require.NotNil(t, m) require.IsType(t, &Minows{}, m) - require.NoError(t, m.(*Minows).stop()) + require.NoError(t, m.(*Minows).Stop()) }) } } @@ -52,7 +52,7 @@ func TestNewMinows_OptionalPublic(t *testing.T) { require.NoError(t, err) require.NotNil(t, m) require.IsType(t, &Minows{}, m) - require.NoError(t, m.(*Minows).stop()) + require.NoError(t, m.(*Minows).Stop()) }) } @@ -113,7 +113,7 @@ func Test_minows_GetAddress(t *testing.T) { m, err := NewMinows(manager, mustCreateMultiaddress(t, tt.m.listen), mustCreateMultiaddress(t, tt.m.public), tt.m.key) require.NoError(t, err) - defer require.NoError(t, m.(*Minows).stop()) + defer require.NoError(t, m.(*Minows).Stop()) want := mustCreateAddress(t, tt.want.location, tt.want.identity) got := m.GetAddress() @@ -129,7 +129,7 @@ func Test_minows_GetAddress_Random(t *testing.T) { manager := NewManager() m, err := NewMinows(manager, listen, nil, key) require.NoError(t, err) - defer require.NoError(t, m.(*Minows).stop()) + defer require.NoError(t, m.(*Minows).Stop()) got := m.GetAddress().(address) port, err := got.location.ValueForProtocol(ma.P_TCP) @@ -227,7 +227,7 @@ func mustCreateMinows(t *testing.T, listen string, public string) ( m, err := NewMinows(manager, lis, pub, key) require.NoError(t, err) ws := m.(*Minows) - stop := func() { require.NoError(t, ws.stop()) } + stop := func() { require.NoError(t, ws.Stop()) } return ws, stop }