From 83ea0308a2b776cb232943699881fbe71ea40418 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Thu, 9 Feb 2023 15:40:48 +1100 Subject: [PATCH] remove circuitv1 protocol implementation --- limits.go | 13 - p2p/protocol/circuitv1/pb/circuitv1.pb.go | 448 --------------------- p2p/protocol/circuitv1/pb/circuitv1.proto | 44 --- p2p/protocol/circuitv1/proto.go | 3 - p2p/protocol/circuitv1/relay/options.go | 46 --- p2p/protocol/circuitv1/relay/relay.go | 452 ---------------------- 6 files changed, 1006 deletions(-) delete mode 100644 p2p/protocol/circuitv1/pb/circuitv1.pb.go delete mode 100644 p2p/protocol/circuitv1/pb/circuitv1.proto delete mode 100644 p2p/protocol/circuitv1/proto.go delete mode 100644 p2p/protocol/circuitv1/relay/options.go delete mode 100644 p2p/protocol/circuitv1/relay/relay.go diff --git a/limits.go b/limits.go index 63ac670301..5871577e51 100644 --- a/limits.go +++ b/limits.go @@ -4,7 +4,6 @@ import ( "github.com/libp2p/go-libp2p/core/protocol" "github.com/libp2p/go-libp2p/p2p/host/autonat" rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager" - relayv1 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv1/relay" circuit "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/proto" relayv2 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/relay" "github.com/libp2p/go-libp2p/p2p/protocol/holepunch" @@ -76,18 +75,6 @@ func SetDefaultServiceLimits(config *rcmgr.ScalingLimitConfig) { rcmgr.BaseLimitIncrease{}, ) - // relay/v1 - config.AddServiceLimit( - relayv1.ServiceName, - rcmgr.BaseLimit{StreamsInbound: 256, StreamsOutbound: 256, Streams: 256, Memory: 16 << 20}, - rcmgr.BaseLimitIncrease{StreamsInbound: 256, StreamsOutbound: 256, Streams: 256, Memory: 16 << 20}, - ) - config.AddServicePeerLimit( - relayv1.ServiceName, - rcmgr.BaseLimit{StreamsInbound: 64, StreamsOutbound: 64, Streams: 64, Memory: 1 << 20}, - rcmgr.BaseLimitIncrease{}, - ) - // relay/v2 config.AddServiceLimit( relayv2.ServiceName, diff --git a/p2p/protocol/circuitv1/pb/circuitv1.pb.go b/p2p/protocol/circuitv1/pb/circuitv1.pb.go deleted file mode 100644 index 1fe5eaa91b..0000000000 --- a/p2p/protocol/circuitv1/pb/circuitv1.pb.go +++ /dev/null @@ -1,448 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.28.1 -// protoc v3.21.12 -// source: pb/circuitv1.proto - -package pb - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -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) -) - -type CircuitRelay_Status int32 - -const ( - CircuitRelay_SUCCESS CircuitRelay_Status = 100 - CircuitRelay_HOP_SRC_ADDR_TOO_LONG CircuitRelay_Status = 220 - CircuitRelay_HOP_DST_ADDR_TOO_LONG CircuitRelay_Status = 221 - CircuitRelay_HOP_SRC_MULTIADDR_INVALID CircuitRelay_Status = 250 - CircuitRelay_HOP_DST_MULTIADDR_INVALID CircuitRelay_Status = 251 - CircuitRelay_HOP_NO_CONN_TO_DST CircuitRelay_Status = 260 - CircuitRelay_HOP_CANT_DIAL_DST CircuitRelay_Status = 261 - CircuitRelay_HOP_CANT_OPEN_DST_STREAM CircuitRelay_Status = 262 - CircuitRelay_HOP_CANT_SPEAK_RELAY CircuitRelay_Status = 270 - CircuitRelay_HOP_CANT_RELAY_TO_SELF CircuitRelay_Status = 280 - CircuitRelay_STOP_SRC_ADDR_TOO_LONG CircuitRelay_Status = 320 - CircuitRelay_STOP_DST_ADDR_TOO_LONG CircuitRelay_Status = 321 - CircuitRelay_STOP_SRC_MULTIADDR_INVALID CircuitRelay_Status = 350 - CircuitRelay_STOP_DST_MULTIADDR_INVALID CircuitRelay_Status = 351 - CircuitRelay_STOP_RELAY_REFUSED CircuitRelay_Status = 390 - CircuitRelay_MALFORMED_MESSAGE CircuitRelay_Status = 400 -) - -// Enum value maps for CircuitRelay_Status. -var ( - CircuitRelay_Status_name = map[int32]string{ - 100: "SUCCESS", - 220: "HOP_SRC_ADDR_TOO_LONG", - 221: "HOP_DST_ADDR_TOO_LONG", - 250: "HOP_SRC_MULTIADDR_INVALID", - 251: "HOP_DST_MULTIADDR_INVALID", - 260: "HOP_NO_CONN_TO_DST", - 261: "HOP_CANT_DIAL_DST", - 262: "HOP_CANT_OPEN_DST_STREAM", - 270: "HOP_CANT_SPEAK_RELAY", - 280: "HOP_CANT_RELAY_TO_SELF", - 320: "STOP_SRC_ADDR_TOO_LONG", - 321: "STOP_DST_ADDR_TOO_LONG", - 350: "STOP_SRC_MULTIADDR_INVALID", - 351: "STOP_DST_MULTIADDR_INVALID", - 390: "STOP_RELAY_REFUSED", - 400: "MALFORMED_MESSAGE", - } - CircuitRelay_Status_value = map[string]int32{ - "SUCCESS": 100, - "HOP_SRC_ADDR_TOO_LONG": 220, - "HOP_DST_ADDR_TOO_LONG": 221, - "HOP_SRC_MULTIADDR_INVALID": 250, - "HOP_DST_MULTIADDR_INVALID": 251, - "HOP_NO_CONN_TO_DST": 260, - "HOP_CANT_DIAL_DST": 261, - "HOP_CANT_OPEN_DST_STREAM": 262, - "HOP_CANT_SPEAK_RELAY": 270, - "HOP_CANT_RELAY_TO_SELF": 280, - "STOP_SRC_ADDR_TOO_LONG": 320, - "STOP_DST_ADDR_TOO_LONG": 321, - "STOP_SRC_MULTIADDR_INVALID": 350, - "STOP_DST_MULTIADDR_INVALID": 351, - "STOP_RELAY_REFUSED": 390, - "MALFORMED_MESSAGE": 400, - } -) - -func (x CircuitRelay_Status) Enum() *CircuitRelay_Status { - p := new(CircuitRelay_Status) - *p = x - return p -} - -func (x CircuitRelay_Status) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (CircuitRelay_Status) Descriptor() protoreflect.EnumDescriptor { - return file_pb_circuitv1_proto_enumTypes[0].Descriptor() -} - -func (CircuitRelay_Status) Type() protoreflect.EnumType { - return &file_pb_circuitv1_proto_enumTypes[0] -} - -func (x CircuitRelay_Status) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Do not use. -func (x *CircuitRelay_Status) UnmarshalJSON(b []byte) error { - num, err := protoimpl.X.UnmarshalJSONEnum(x.Descriptor(), b) - if err != nil { - return err - } - *x = CircuitRelay_Status(num) - return nil -} - -// Deprecated: Use CircuitRelay_Status.Descriptor instead. -func (CircuitRelay_Status) EnumDescriptor() ([]byte, []int) { - return file_pb_circuitv1_proto_rawDescGZIP(), []int{0, 0} -} - -type CircuitRelay_Type int32 - -const ( - CircuitRelay_HOP CircuitRelay_Type = 1 - CircuitRelay_STOP CircuitRelay_Type = 2 - CircuitRelay_STATUS CircuitRelay_Type = 3 - CircuitRelay_CAN_HOP CircuitRelay_Type = 4 -) - -// Enum value maps for CircuitRelay_Type. -var ( - CircuitRelay_Type_name = map[int32]string{ - 1: "HOP", - 2: "STOP", - 3: "STATUS", - 4: "CAN_HOP", - } - CircuitRelay_Type_value = map[string]int32{ - "HOP": 1, - "STOP": 2, - "STATUS": 3, - "CAN_HOP": 4, - } -) - -func (x CircuitRelay_Type) Enum() *CircuitRelay_Type { - p := new(CircuitRelay_Type) - *p = x - return p -} - -func (x CircuitRelay_Type) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (CircuitRelay_Type) Descriptor() protoreflect.EnumDescriptor { - return file_pb_circuitv1_proto_enumTypes[1].Descriptor() -} - -func (CircuitRelay_Type) Type() protoreflect.EnumType { - return &file_pb_circuitv1_proto_enumTypes[1] -} - -func (x CircuitRelay_Type) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Do not use. -func (x *CircuitRelay_Type) UnmarshalJSON(b []byte) error { - num, err := protoimpl.X.UnmarshalJSONEnum(x.Descriptor(), b) - if err != nil { - return err - } - *x = CircuitRelay_Type(num) - return nil -} - -// Deprecated: Use CircuitRelay_Type.Descriptor instead. -func (CircuitRelay_Type) EnumDescriptor() ([]byte, []int) { - return file_pb_circuitv1_proto_rawDescGZIP(), []int{0, 1} -} - -type CircuitRelay struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Type *CircuitRelay_Type `protobuf:"varint,1,opt,name=type,enum=circuitv1.pb.CircuitRelay_Type" json:"type,omitempty"` // Type of the message - SrcPeer *CircuitRelay_Peer `protobuf:"bytes,2,opt,name=srcPeer" json:"srcPeer,omitempty"` // srcPeer and dstPeer are used when Type is HOP or STOP - DstPeer *CircuitRelay_Peer `protobuf:"bytes,3,opt,name=dstPeer" json:"dstPeer,omitempty"` - Code *CircuitRelay_Status `protobuf:"varint,4,opt,name=code,enum=circuitv1.pb.CircuitRelay_Status" json:"code,omitempty"` // Status code, used when Type is STATUS -} - -func (x *CircuitRelay) Reset() { - *x = CircuitRelay{} - if protoimpl.UnsafeEnabled { - mi := &file_pb_circuitv1_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CircuitRelay) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CircuitRelay) ProtoMessage() {} - -func (x *CircuitRelay) ProtoReflect() protoreflect.Message { - mi := &file_pb_circuitv1_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use CircuitRelay.ProtoReflect.Descriptor instead. -func (*CircuitRelay) Descriptor() ([]byte, []int) { - return file_pb_circuitv1_proto_rawDescGZIP(), []int{0} -} - -func (x *CircuitRelay) GetType() CircuitRelay_Type { - if x != nil && x.Type != nil { - return *x.Type - } - return CircuitRelay_HOP -} - -func (x *CircuitRelay) GetSrcPeer() *CircuitRelay_Peer { - if x != nil { - return x.SrcPeer - } - return nil -} - -func (x *CircuitRelay) GetDstPeer() *CircuitRelay_Peer { - if x != nil { - return x.DstPeer - } - return nil -} - -func (x *CircuitRelay) GetCode() CircuitRelay_Status { - if x != nil && x.Code != nil { - return *x.Code - } - return CircuitRelay_SUCCESS -} - -type CircuitRelay_Peer struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id []byte `protobuf:"bytes,1,req,name=id" json:"id,omitempty"` // peer id - Addrs [][]byte `protobuf:"bytes,2,rep,name=addrs" json:"addrs,omitempty"` // peer's known addresses -} - -func (x *CircuitRelay_Peer) Reset() { - *x = CircuitRelay_Peer{} - if protoimpl.UnsafeEnabled { - mi := &file_pb_circuitv1_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CircuitRelay_Peer) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CircuitRelay_Peer) ProtoMessage() {} - -func (x *CircuitRelay_Peer) ProtoReflect() protoreflect.Message { - mi := &file_pb_circuitv1_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use CircuitRelay_Peer.ProtoReflect.Descriptor instead. -func (*CircuitRelay_Peer) Descriptor() ([]byte, []int) { - return file_pb_circuitv1_proto_rawDescGZIP(), []int{0, 0} -} - -func (x *CircuitRelay_Peer) GetId() []byte { - if x != nil { - return x.Id - } - return nil -} - -func (x *CircuitRelay_Peer) GetAddrs() [][]byte { - if x != nil { - return x.Addrs - } - return nil -} - -var File_pb_circuitv1_proto protoreflect.FileDescriptor - -var file_pb_circuitv1_proto_rawDesc = []byte{ - 0x0a, 0x12, 0x70, 0x62, 0x2f, 0x63, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x76, 0x31, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, 0x63, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x76, 0x31, 0x2e, - 0x70, 0x62, 0x22, 0x97, 0x06, 0x0a, 0x0c, 0x43, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x52, 0x65, - 0x6c, 0x61, 0x79, 0x12, 0x33, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0e, 0x32, 0x1f, 0x2e, 0x63, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x76, 0x31, 0x2e, 0x70, 0x62, - 0x2e, 0x43, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x52, 0x65, 0x6c, 0x61, 0x79, 0x2e, 0x54, 0x79, - 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x39, 0x0a, 0x07, 0x73, 0x72, 0x63, 0x50, - 0x65, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x63, 0x69, 0x72, 0x63, - 0x75, 0x69, 0x74, 0x76, 0x31, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, - 0x52, 0x65, 0x6c, 0x61, 0x79, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x52, 0x07, 0x73, 0x72, 0x63, 0x50, - 0x65, 0x65, 0x72, 0x12, 0x39, 0x0a, 0x07, 0x64, 0x73, 0x74, 0x50, 0x65, 0x65, 0x72, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x63, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x76, 0x31, - 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x52, 0x65, 0x6c, 0x61, 0x79, - 0x2e, 0x50, 0x65, 0x65, 0x72, 0x52, 0x07, 0x64, 0x73, 0x74, 0x50, 0x65, 0x65, 0x72, 0x12, 0x35, - 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x21, 0x2e, 0x63, - 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x76, 0x31, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x69, 0x72, 0x63, - 0x75, 0x69, 0x74, 0x52, 0x65, 0x6c, 0x61, 0x79, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, - 0x04, 0x63, 0x6f, 0x64, 0x65, 0x1a, 0x2c, 0x0a, 0x04, 0x50, 0x65, 0x65, 0x72, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x02, 0x28, 0x0c, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, - 0x05, 0x61, 0x64, 0x64, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x05, 0x61, 0x64, - 0x64, 0x72, 0x73, 0x22, 0xc2, 0x03, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0b, - 0x0a, 0x07, 0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x10, 0x64, 0x12, 0x1a, 0x0a, 0x15, 0x48, - 0x4f, 0x50, 0x5f, 0x53, 0x52, 0x43, 0x5f, 0x41, 0x44, 0x44, 0x52, 0x5f, 0x54, 0x4f, 0x4f, 0x5f, - 0x4c, 0x4f, 0x4e, 0x47, 0x10, 0xdc, 0x01, 0x12, 0x1a, 0x0a, 0x15, 0x48, 0x4f, 0x50, 0x5f, 0x44, - 0x53, 0x54, 0x5f, 0x41, 0x44, 0x44, 0x52, 0x5f, 0x54, 0x4f, 0x4f, 0x5f, 0x4c, 0x4f, 0x4e, 0x47, - 0x10, 0xdd, 0x01, 0x12, 0x1e, 0x0a, 0x19, 0x48, 0x4f, 0x50, 0x5f, 0x53, 0x52, 0x43, 0x5f, 0x4d, - 0x55, 0x4c, 0x54, 0x49, 0x41, 0x44, 0x44, 0x52, 0x5f, 0x49, 0x4e, 0x56, 0x41, 0x4c, 0x49, 0x44, - 0x10, 0xfa, 0x01, 0x12, 0x1e, 0x0a, 0x19, 0x48, 0x4f, 0x50, 0x5f, 0x44, 0x53, 0x54, 0x5f, 0x4d, - 0x55, 0x4c, 0x54, 0x49, 0x41, 0x44, 0x44, 0x52, 0x5f, 0x49, 0x4e, 0x56, 0x41, 0x4c, 0x49, 0x44, - 0x10, 0xfb, 0x01, 0x12, 0x17, 0x0a, 0x12, 0x48, 0x4f, 0x50, 0x5f, 0x4e, 0x4f, 0x5f, 0x43, 0x4f, - 0x4e, 0x4e, 0x5f, 0x54, 0x4f, 0x5f, 0x44, 0x53, 0x54, 0x10, 0x84, 0x02, 0x12, 0x16, 0x0a, 0x11, - 0x48, 0x4f, 0x50, 0x5f, 0x43, 0x41, 0x4e, 0x54, 0x5f, 0x44, 0x49, 0x41, 0x4c, 0x5f, 0x44, 0x53, - 0x54, 0x10, 0x85, 0x02, 0x12, 0x1d, 0x0a, 0x18, 0x48, 0x4f, 0x50, 0x5f, 0x43, 0x41, 0x4e, 0x54, - 0x5f, 0x4f, 0x50, 0x45, 0x4e, 0x5f, 0x44, 0x53, 0x54, 0x5f, 0x53, 0x54, 0x52, 0x45, 0x41, 0x4d, - 0x10, 0x86, 0x02, 0x12, 0x19, 0x0a, 0x14, 0x48, 0x4f, 0x50, 0x5f, 0x43, 0x41, 0x4e, 0x54, 0x5f, - 0x53, 0x50, 0x45, 0x41, 0x4b, 0x5f, 0x52, 0x45, 0x4c, 0x41, 0x59, 0x10, 0x8e, 0x02, 0x12, 0x1b, - 0x0a, 0x16, 0x48, 0x4f, 0x50, 0x5f, 0x43, 0x41, 0x4e, 0x54, 0x5f, 0x52, 0x45, 0x4c, 0x41, 0x59, - 0x5f, 0x54, 0x4f, 0x5f, 0x53, 0x45, 0x4c, 0x46, 0x10, 0x98, 0x02, 0x12, 0x1b, 0x0a, 0x16, 0x53, - 0x54, 0x4f, 0x50, 0x5f, 0x53, 0x52, 0x43, 0x5f, 0x41, 0x44, 0x44, 0x52, 0x5f, 0x54, 0x4f, 0x4f, - 0x5f, 0x4c, 0x4f, 0x4e, 0x47, 0x10, 0xc0, 0x02, 0x12, 0x1b, 0x0a, 0x16, 0x53, 0x54, 0x4f, 0x50, - 0x5f, 0x44, 0x53, 0x54, 0x5f, 0x41, 0x44, 0x44, 0x52, 0x5f, 0x54, 0x4f, 0x4f, 0x5f, 0x4c, 0x4f, - 0x4e, 0x47, 0x10, 0xc1, 0x02, 0x12, 0x1f, 0x0a, 0x1a, 0x53, 0x54, 0x4f, 0x50, 0x5f, 0x53, 0x52, - 0x43, 0x5f, 0x4d, 0x55, 0x4c, 0x54, 0x49, 0x41, 0x44, 0x44, 0x52, 0x5f, 0x49, 0x4e, 0x56, 0x41, - 0x4c, 0x49, 0x44, 0x10, 0xde, 0x02, 0x12, 0x1f, 0x0a, 0x1a, 0x53, 0x54, 0x4f, 0x50, 0x5f, 0x44, - 0x53, 0x54, 0x5f, 0x4d, 0x55, 0x4c, 0x54, 0x49, 0x41, 0x44, 0x44, 0x52, 0x5f, 0x49, 0x4e, 0x56, - 0x41, 0x4c, 0x49, 0x44, 0x10, 0xdf, 0x02, 0x12, 0x17, 0x0a, 0x12, 0x53, 0x54, 0x4f, 0x50, 0x5f, - 0x52, 0x45, 0x4c, 0x41, 0x59, 0x5f, 0x52, 0x45, 0x46, 0x55, 0x53, 0x45, 0x44, 0x10, 0x86, 0x03, - 0x12, 0x16, 0x0a, 0x11, 0x4d, 0x41, 0x4c, 0x46, 0x4f, 0x52, 0x4d, 0x45, 0x44, 0x5f, 0x4d, 0x45, - 0x53, 0x53, 0x41, 0x47, 0x45, 0x10, 0x90, 0x03, 0x22, 0x32, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, - 0x12, 0x07, 0x0a, 0x03, 0x48, 0x4f, 0x50, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x53, 0x54, 0x4f, - 0x50, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x10, 0x03, 0x12, - 0x0b, 0x0a, 0x07, 0x43, 0x41, 0x4e, 0x5f, 0x48, 0x4f, 0x50, 0x10, 0x04, -} - -var ( - file_pb_circuitv1_proto_rawDescOnce sync.Once - file_pb_circuitv1_proto_rawDescData = file_pb_circuitv1_proto_rawDesc -) - -func file_pb_circuitv1_proto_rawDescGZIP() []byte { - file_pb_circuitv1_proto_rawDescOnce.Do(func() { - file_pb_circuitv1_proto_rawDescData = protoimpl.X.CompressGZIP(file_pb_circuitv1_proto_rawDescData) - }) - return file_pb_circuitv1_proto_rawDescData -} - -var file_pb_circuitv1_proto_enumTypes = make([]protoimpl.EnumInfo, 2) -var file_pb_circuitv1_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_pb_circuitv1_proto_goTypes = []interface{}{ - (CircuitRelay_Status)(0), // 0: circuitv1.pb.CircuitRelay.Status - (CircuitRelay_Type)(0), // 1: circuitv1.pb.CircuitRelay.Type - (*CircuitRelay)(nil), // 2: circuitv1.pb.CircuitRelay - (*CircuitRelay_Peer)(nil), // 3: circuitv1.pb.CircuitRelay.Peer -} -var file_pb_circuitv1_proto_depIdxs = []int32{ - 1, // 0: circuitv1.pb.CircuitRelay.type:type_name -> circuitv1.pb.CircuitRelay.Type - 3, // 1: circuitv1.pb.CircuitRelay.srcPeer:type_name -> circuitv1.pb.CircuitRelay.Peer - 3, // 2: circuitv1.pb.CircuitRelay.dstPeer:type_name -> circuitv1.pb.CircuitRelay.Peer - 0, // 3: circuitv1.pb.CircuitRelay.code:type_name -> circuitv1.pb.CircuitRelay.Status - 4, // [4:4] is the sub-list for method output_type - 4, // [4:4] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name -} - -func init() { file_pb_circuitv1_proto_init() } -func file_pb_circuitv1_proto_init() { - if File_pb_circuitv1_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_pb_circuitv1_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CircuitRelay); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_pb_circuitv1_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CircuitRelay_Peer); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_pb_circuitv1_proto_rawDesc, - NumEnums: 2, - NumMessages: 2, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_pb_circuitv1_proto_goTypes, - DependencyIndexes: file_pb_circuitv1_proto_depIdxs, - EnumInfos: file_pb_circuitv1_proto_enumTypes, - MessageInfos: file_pb_circuitv1_proto_msgTypes, - }.Build() - File_pb_circuitv1_proto = out.File - file_pb_circuitv1_proto_rawDesc = nil - file_pb_circuitv1_proto_goTypes = nil - file_pb_circuitv1_proto_depIdxs = nil -} diff --git a/p2p/protocol/circuitv1/pb/circuitv1.proto b/p2p/protocol/circuitv1/pb/circuitv1.proto deleted file mode 100644 index c591f0751a..0000000000 --- a/p2p/protocol/circuitv1/pb/circuitv1.proto +++ /dev/null @@ -1,44 +0,0 @@ -syntax = "proto2"; - -package circuitv1.pb; - -message CircuitRelay { - - enum Status { - SUCCESS = 100; - HOP_SRC_ADDR_TOO_LONG = 220; - HOP_DST_ADDR_TOO_LONG = 221; - HOP_SRC_MULTIADDR_INVALID = 250; - HOP_DST_MULTIADDR_INVALID = 251; - HOP_NO_CONN_TO_DST = 260; - HOP_CANT_DIAL_DST = 261; - HOP_CANT_OPEN_DST_STREAM = 262; - HOP_CANT_SPEAK_RELAY = 270; - HOP_CANT_RELAY_TO_SELF = 280; - STOP_SRC_ADDR_TOO_LONG = 320; - STOP_DST_ADDR_TOO_LONG = 321; - STOP_SRC_MULTIADDR_INVALID = 350; - STOP_DST_MULTIADDR_INVALID = 351; - STOP_RELAY_REFUSED = 390; - MALFORMED_MESSAGE = 400; - } - - enum Type { // RPC identifier, either HOP, STOP or STATUS - HOP = 1; - STOP = 2; - STATUS = 3; - CAN_HOP = 4; - } - - message Peer { - required bytes id = 1; // peer id - repeated bytes addrs = 2; // peer's known addresses - } - - optional Type type = 1; // Type of the message - - optional Peer srcPeer = 2; // srcPeer and dstPeer are used when Type is HOP or STOP - optional Peer dstPeer = 3; - - optional Status code = 4; // Status code, used when Type is STATUS -} diff --git a/p2p/protocol/circuitv1/proto.go b/p2p/protocol/circuitv1/proto.go deleted file mode 100644 index 9d2f0b2a69..0000000000 --- a/p2p/protocol/circuitv1/proto.go +++ /dev/null @@ -1,3 +0,0 @@ -package circuitv1 - -//go:generate protoc --proto_path=$PWD:$PWD/../../.. --go_out=. --go_opt=Mpb/circuitv1.proto=./pb pb/circuitv1.proto diff --git a/p2p/protocol/circuitv1/relay/options.go b/p2p/protocol/circuitv1/relay/options.go deleted file mode 100644 index bfd2ed895f..0000000000 --- a/p2p/protocol/circuitv1/relay/options.go +++ /dev/null @@ -1,46 +0,0 @@ -package relay - -import ( - "github.com/libp2p/go-libp2p/core/peer" -) - -type Resources struct { - // MaxCircuits is the maximum number of active relay connections - MaxCircuits int - - // MaxCircuitsPerPeer is the maximum number of active relay connections per peer - MaxCircuitsPerPeer int - - // BufferSize is the buffer size for relaying in each direction - BufferSize int -} - -func DefaultResources() Resources { - return Resources{ - MaxCircuits: 1024, - MaxCircuitsPerPeer: 64, - BufferSize: 4096, - } -} - -type ACLFilter interface { - AllowHop(src, dest peer.ID) bool -} - -type Option func(r *Relay) error - -// WithResources specifies resource limits for the relay -func WithResources(rc Resources) Option { - return func(r *Relay) error { - r.rc = rc - return nil - } -} - -// WithACL specifies an ACLFilter for access control -func WithACL(acl ACLFilter) Option { - return func(r *Relay) error { - r.acl = acl - return nil - } -} diff --git a/p2p/protocol/circuitv1/relay/relay.go b/p2p/protocol/circuitv1/relay/relay.go deleted file mode 100644 index 3b6f7adc85..0000000000 --- a/p2p/protocol/circuitv1/relay/relay.go +++ /dev/null @@ -1,452 +0,0 @@ -package relay - -import ( - "context" - "fmt" - "io" - "sync" - "sync/atomic" - "time" - - "github.com/libp2p/go-libp2p/core/host" - "github.com/libp2p/go-libp2p/core/network" - "github.com/libp2p/go-libp2p/core/peer" - pb "github.com/libp2p/go-libp2p/p2p/protocol/circuitv1/pb" - "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/util" - - logging "github.com/ipfs/go-log/v2" - pool "github.com/libp2p/go-buffer-pool" - ma "github.com/multiformats/go-multiaddr" -) - -var log = logging.Logger("relay") - -const ( - ProtoID = "/libp2p/circuit/relay/0.1.0" - - ServiceName = "libp2p.relay/v1" - - StreamTimeout = time.Minute - ConnectTimeout = 30 * time.Second - HandshakeTimeout = time.Minute - - relayHopTag = "relay-v1-hop" - relayHopTagValue = 2 - - maxMessageSize = 4096 -) - -type Relay struct { - closed int32 - ctx context.Context - cancel context.CancelFunc - - host host.Host - rc Resources - acl ACLFilter - scope network.ResourceScopeSpan - - mx sync.Mutex - conns map[peer.ID]int - active int -} - -func NewRelay(h host.Host, opts ...Option) (*Relay, error) { - r := &Relay{ - host: h, - rc: DefaultResources(), - conns: make(map[peer.ID]int), - } - r.ctx, r.cancel = context.WithCancel(context.Background()) - - for _, opt := range opts { - err := opt(r) - if err != nil { - return nil, fmt.Errorf("error applying relay option: %w", err) - } - } - - // get a scope for memory reservations at service level - err := h.Network().ResourceManager().ViewService(ServiceName, - func(s network.ServiceScope) error { - var err error - r.scope, err = s.BeginSpan() - return err - }) - if err != nil { - return nil, err - } - - h.SetStreamHandler(ProtoID, r.handleStream) - - return r, nil -} - -func (r *Relay) Close() error { - if atomic.CompareAndSwapInt32(&r.closed, 0, 1) { - r.host.RemoveStreamHandler(ProtoID) - r.scope.Done() - r.cancel() - } - return nil -} - -func (r *Relay) handleStream(s network.Stream) { - log.Debugf("new relay stream from: %s", s.Conn().RemotePeer()) - - if err := s.Scope().SetService(ServiceName); err != nil { - log.Debugf("error attaching stream to relay service: %s", err) - s.Reset() - return - } - - if err := s.Scope().ReserveMemory(maxMessageSize, network.ReservationPriorityAlways); err != nil { - log.Debugf("error reserving memory for stream: %s", err) - s.Reset() - return - } - defer s.Scope().ReleaseMemory(maxMessageSize) - - rd := util.NewDelimitedReader(s, maxMessageSize) - defer rd.Close() - - s.SetReadDeadline(time.Now().Add(StreamTimeout)) - - var msg pb.CircuitRelay - - err := rd.ReadMsg(&msg) - if err != nil { - r.handleError(s, pb.CircuitRelay_MALFORMED_MESSAGE) - return - } - s.SetReadDeadline(time.Time{}) - - switch msg.GetType() { - case pb.CircuitRelay_HOP: - r.handleHopStream(s, &msg) - case pb.CircuitRelay_CAN_HOP: - r.handleCanHop(s, &msg) - case pb.CircuitRelay_STOP: - r.handleError(s, pb.CircuitRelay_STOP_RELAY_REFUSED) - default: - log.Warnf("unexpected relay handshake: %d", msg.GetType()) - r.handleError(s, pb.CircuitRelay_MALFORMED_MESSAGE) - } -} - -func (r *Relay) handleHopStream(s network.Stream, msg *pb.CircuitRelay) { - span, err := r.scope.BeginSpan() - if err != nil { - log.Debugf("failed to begin relay transaction: %s", err) - r.handleError(s, pb.CircuitRelay_HOP_CANT_SPEAK_RELAY) - return - } - - fail := func(code pb.CircuitRelay_Status) { - span.Done() - r.handleError(s, code) - } - - // reserve buffers for the relay - if err := span.ReserveMemory(2*r.rc.BufferSize, network.ReservationPriorityHigh); err != nil { - log.Debugf("error reserving memory for relay: %s", err) - fail(pb.CircuitRelay_HOP_CANT_SPEAK_RELAY) - return - } - - src, err := peerToPeerInfo(msg.GetSrcPeer()) - if err != nil { - fail(pb.CircuitRelay_HOP_SRC_MULTIADDR_INVALID) - return - } - - if src.ID != s.Conn().RemotePeer() { - fail(pb.CircuitRelay_HOP_SRC_MULTIADDR_INVALID) - return - } - - dest, err := peerToPeerInfo(msg.GetDstPeer()) - if err != nil { - fail(pb.CircuitRelay_HOP_DST_MULTIADDR_INVALID) - return - } - - if dest.ID == r.host.ID() { - fail(pb.CircuitRelay_HOP_CANT_RELAY_TO_SELF) - return - } - - if r.acl != nil && !r.acl.AllowHop(src.ID, dest.ID) { - log.Debugf("refusing hop from %s to %s; ACL refused", src.ID, dest.ID) - fail(pb.CircuitRelay_HOP_CANT_SPEAK_RELAY) - return - } - - r.mx.Lock() - if r.active >= r.rc.MaxCircuits { - r.mx.Unlock() - log.Debugf("refusing connection from %s to %s; too many active circuits", src.ID, dest.ID) - fail(pb.CircuitRelay_HOP_CANT_SPEAK_RELAY) - return - } - - srcConns := r.conns[src.ID] - if srcConns >= r.rc.MaxCircuitsPerPeer { - r.mx.Unlock() - log.Debugf("refusing connection from %s to %s; too many connections from %s", src.ID, dest.ID, src) - fail(pb.CircuitRelay_HOP_CANT_SPEAK_RELAY) - return - } - - destConns := r.conns[dest.ID] - if destConns >= r.rc.MaxCircuitsPerPeer { - r.mx.Unlock() - log.Debugf("refusing connection from %s to %s; too many connecitons to %s", src.ID, dest.ID, dest.ID) - fail(pb.CircuitRelay_HOP_CANT_SPEAK_RELAY) - return - } - - r.active++ - r.addConn(src.ID) - r.addConn(src.ID) - r.mx.Unlock() - - cleanup := func() { - span.Done() - r.mx.Lock() - r.active-- - r.rmConn(src.ID) - r.rmConn(dest.ID) - r.mx.Unlock() - } - - // open stream - ctx, cancel := context.WithTimeout(r.ctx, ConnectTimeout) - defer cancel() - - ctx = network.WithNoDial(ctx, "relay hop") - bs, err := r.host.NewStream(ctx, dest.ID, ProtoID) - if err != nil { - log.Debugf("error opening relay stream to %s: %s", dest.ID.Pretty(), err.Error()) - if err == network.ErrNoConn { - r.handleError(s, pb.CircuitRelay_HOP_NO_CONN_TO_DST) - } else { - r.handleError(s, pb.CircuitRelay_HOP_CANT_DIAL_DST) - } - cleanup() - return - } - - fail = func(code pb.CircuitRelay_Status) { - bs.Reset() - cleanup() - r.handleError(s, code) - } - - if err := bs.Scope().SetService(ServiceName); err != nil { - log.Debugf("error attaching stream to relay service: %s", err) - fail(pb.CircuitRelay_HOP_CANT_SPEAK_RELAY) - return - } - - // stop handshake - if err := bs.Scope().ReserveMemory(maxMessageSize, network.ReservationPriorityAlways); err != nil { - log.Debugf("failed to reserve memory for stream: %s", err) - fail(pb.CircuitRelay_HOP_CANT_SPEAK_RELAY) - return - } - defer bs.Scope().ReleaseMemory(maxMessageSize) - - rd := util.NewDelimitedReader(bs, maxMessageSize) - wr := util.NewDelimitedWriter(bs) - defer rd.Close() - - // set handshake deadline - bs.SetDeadline(time.Now().Add(HandshakeTimeout)) - - msg.Type = pb.CircuitRelay_STOP.Enum() - - err = wr.WriteMsg(msg) - if err != nil { - log.Debugf("error writing stop handshake: %s", err.Error()) - fail(pb.CircuitRelay_HOP_CANT_OPEN_DST_STREAM) - return - } - - msg.Reset() - - err = rd.ReadMsg(msg) - if err != nil { - log.Debugf("error reading stop response: %s", err.Error()) - fail(pb.CircuitRelay_HOP_CANT_OPEN_DST_STREAM) - return - } - - if msg.GetType() != pb.CircuitRelay_STATUS { - log.Debugf("unexpected relay stop response: not a status message (%d)", msg.GetType()) - fail(pb.CircuitRelay_HOP_CANT_OPEN_DST_STREAM) - return - } - - if msg.GetCode() != pb.CircuitRelay_SUCCESS { - log.Debugf("relay stop failure: %d", msg.GetCode()) - fail(msg.GetCode()) - return - } - - err = r.writeResponse(s, pb.CircuitRelay_SUCCESS) - if err != nil { - log.Debugf("error writing relay response: %s", err.Error()) - bs.Reset() - s.Reset() - cleanup() - return - } - - // relay connection - log.Infof("relaying connection between %s and %s", src.ID.Pretty(), dest.ID.Pretty()) - - // reset deadline - bs.SetDeadline(time.Time{}) - - goroutines := new(int32) - *goroutines = 2 - done := func() { - if atomic.AddInt32(goroutines, -1) == 0 { - s.Close() - bs.Close() - cleanup() - } - } - - go r.relayConn(s, bs, src.ID, dest.ID, done) - go r.relayConn(bs, s, dest.ID, src.ID, done) -} - -func (r *Relay) addConn(p peer.ID) { - conns := r.conns[p] - conns++ - r.conns[p] = conns - if conns == 1 { - r.host.ConnManager().TagPeer(p, relayHopTag, relayHopTagValue) - } -} - -func (r *Relay) rmConn(p peer.ID) { - conns := r.conns[p] - conns-- - if conns > 0 { - r.conns[p] = conns - } else { - delete(r.conns, p) - r.host.ConnManager().UntagPeer(p, relayHopTag) - } -} - -func (r *Relay) relayConn(src, dest network.Stream, srcID, destID peer.ID, done func()) { - defer done() - - buf := pool.Get(r.rc.BufferSize) - defer pool.Put(buf) - - count, err := io.CopyBuffer(dest, src, buf) - if err != nil { - log.Debugf("relay copy error: %s", err) - // Reset both. - src.Reset() - dest.Reset() - } else { - // propagate the close - dest.CloseWrite() - } - - log.Debugf("relayed %d bytes from %s to %s", count, srcID, destID) -} - -func (r *Relay) handleCanHop(s network.Stream, msg *pb.CircuitRelay) { - err := r.writeResponse(s, pb.CircuitRelay_SUCCESS) - - if err != nil { - s.Reset() - log.Debugf("error writing relay response: %s", err.Error()) - } else { - s.Close() - } -} - -func (r *Relay) handleError(s network.Stream, code pb.CircuitRelay_Status) { - log.Warnf("relay error: %s", code) - err := r.writeResponse(s, code) - if err != nil { - s.Reset() - log.Debugf("error writing relay response: %s", err.Error()) - } else { - s.Close() - } -} - -// Queries a peer for support of hop relay -func CanHop(ctx context.Context, host host.Host, id peer.ID) (bool, error) { - s, err := host.NewStream(ctx, id, ProtoID) - if err != nil { - return false, err - } - defer s.Close() - - rd := util.NewDelimitedReader(s, maxMessageSize) - wr := util.NewDelimitedWriter(s) - defer rd.Close() - - var msg pb.CircuitRelay - - msg.Type = pb.CircuitRelay_CAN_HOP.Enum() - - if err := wr.WriteMsg(&msg); err != nil { - s.Reset() - return false, err - } - - msg.Reset() - - if err := rd.ReadMsg(&msg); err != nil { - s.Reset() - return false, err - } - - if msg.GetType() != pb.CircuitRelay_STATUS { - return false, fmt.Errorf("unexpected relay response; not a status message (%d)", msg.GetType()) - } - - return msg.GetCode() == pb.CircuitRelay_SUCCESS, nil -} - -func (r *Relay) writeResponse(s network.Stream, code pb.CircuitRelay_Status) error { - wr := util.NewDelimitedWriter(s) - - var msg pb.CircuitRelay - msg.Type = pb.CircuitRelay_STATUS.Enum() - msg.Code = code.Enum() - - return wr.WriteMsg(&msg) -} - -func peerToPeerInfo(p *pb.CircuitRelay_Peer) (peer.AddrInfo, error) { - if p == nil { - return peer.AddrInfo{}, fmt.Errorf("nil peer") - } - - id, err := peer.IDFromBytes(p.Id) - if err != nil { - return peer.AddrInfo{}, err - } - - addrs := make([]ma.Multiaddr, 0, len(p.Addrs)) - for _, addrBytes := range p.Addrs { - a, err := ma.NewMultiaddrBytes(addrBytes) - if err == nil { - addrs = append(addrs, a) - } - } - - return peer.AddrInfo{ID: id, Addrs: addrs}, nil -}