trying to support notice event
This commit is contained in:
parent
be7f4f4da5
commit
a0efb55c3e
11
client.go
11
client.go
@ -1163,6 +1163,17 @@ start_over:
|
||||
cts.cli.log.Write(cts.Sid, LOG_ERROR, "Invalid peer_data event from %s", cts.remote_addr)
|
||||
}
|
||||
|
||||
case PACKET_KIND_CONN_NOTICE:
|
||||
// the connection from the client to a peer has been established
|
||||
var x *Packet_Notice
|
||||
var ok bool
|
||||
x, ok = pkt.U.(*Packet_Notice)
|
||||
if ok {
|
||||
fmt.Printf ("CONN NOTICE [%s] from %s\n", x.Notice.Text, cts.remote_addr)
|
||||
} else {
|
||||
cts.cli.log.Write(cts.Sid, LOG_ERROR, "Invalid conn_data event from %s", cts.remote_addr)
|
||||
}
|
||||
|
||||
default:
|
||||
// do nothing. ignore the rest
|
||||
}
|
||||
|
4
hodu.go
4
hodu.go
@ -84,6 +84,10 @@ type json_in_cred struct {
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type json_in_notice struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type json_out_go_stats struct {
|
||||
CPUs int `json:"cpus"`
|
||||
Goroutines int `json:"goroutines"`
|
||||
|
169
hodu.pb.go
169
hodu.pb.go
@ -97,6 +97,7 @@ const (
|
||||
PACKET_KIND_PEER_ABORTED PACKET_KIND = 7
|
||||
PACKET_KIND_PEER_EOF PACKET_KIND = 8
|
||||
PACKET_KIND_PEER_DATA PACKET_KIND = 9
|
||||
PACKET_KIND_CONN_NOTICE PACKET_KIND = 10
|
||||
)
|
||||
|
||||
// Enum value maps for PACKET_KIND.
|
||||
@ -112,6 +113,7 @@ var (
|
||||
7: "PEER_ABORTED",
|
||||
8: "PEER_EOF",
|
||||
9: "PEER_DATA",
|
||||
10: "CONN_NOTICE",
|
||||
}
|
||||
PACKET_KIND_value = map[string]int32{
|
||||
"RESERVED": 0,
|
||||
@ -124,6 +126,7 @@ var (
|
||||
"PEER_ABORTED": 7,
|
||||
"PEER_EOF": 8,
|
||||
"PEER_DATA": 9,
|
||||
"CONN_NOTICE": 10,
|
||||
}
|
||||
)
|
||||
|
||||
@ -436,6 +439,51 @@ func (x *PeerData) GetData() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
type ConnNotice struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Text string `protobuf:"bytes,1,opt,name=Text,proto3" json:"Text,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ConnNotice) Reset() {
|
||||
*x = ConnNotice{}
|
||||
mi := &file_hodu_proto_msgTypes[4]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *ConnNotice) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ConnNotice) ProtoMessage() {}
|
||||
|
||||
func (x *ConnNotice) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_hodu_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 ConnNotice.ProtoReflect.Descriptor instead.
|
||||
func (*ConnNotice) Descriptor() ([]byte, []int) {
|
||||
return file_hodu_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *ConnNotice) GetText() string {
|
||||
if x != nil {
|
||||
return x.Text
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type Packet struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -447,12 +495,13 @@ type Packet struct {
|
||||
// *Packet_Route
|
||||
// *Packet_Peer
|
||||
// *Packet_Data
|
||||
// *Packet_Notice
|
||||
U isPacket_U `protobuf_oneof:"U"`
|
||||
}
|
||||
|
||||
func (x *Packet) Reset() {
|
||||
*x = Packet{}
|
||||
mi := &file_hodu_proto_msgTypes[4]
|
||||
mi := &file_hodu_proto_msgTypes[5]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@ -464,7 +513,7 @@ func (x *Packet) String() string {
|
||||
func (*Packet) ProtoMessage() {}
|
||||
|
||||
func (x *Packet) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_hodu_proto_msgTypes[4]
|
||||
mi := &file_hodu_proto_msgTypes[5]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@ -477,7 +526,7 @@ func (x *Packet) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use Packet.ProtoReflect.Descriptor instead.
|
||||
func (*Packet) Descriptor() ([]byte, []int) {
|
||||
return file_hodu_proto_rawDescGZIP(), []int{4}
|
||||
return file_hodu_proto_rawDescGZIP(), []int{5}
|
||||
}
|
||||
|
||||
func (x *Packet) GetKind() PACKET_KIND {
|
||||
@ -515,6 +564,13 @@ func (x *Packet) GetData() *PeerData {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Packet) GetNotice() *ConnNotice {
|
||||
if x, ok := x.GetU().(*Packet_Notice); ok {
|
||||
return x.Notice
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type isPacket_U interface {
|
||||
isPacket_U()
|
||||
}
|
||||
@ -531,12 +587,18 @@ type Packet_Data struct {
|
||||
Data *PeerData `protobuf:"bytes,4,opt,name=Data,proto3,oneof"`
|
||||
}
|
||||
|
||||
type Packet_Notice struct {
|
||||
Notice *ConnNotice `protobuf:"bytes,5,opt,name=Notice,proto3,oneof"`
|
||||
}
|
||||
|
||||
func (*Packet_Route) isPacket_U() {}
|
||||
|
||||
func (*Packet_Peer) isPacket_U() {}
|
||||
|
||||
func (*Packet_Data) isPacket_U() {}
|
||||
|
||||
func (*Packet_Notice) isPacket_U() {}
|
||||
|
||||
var File_hodu_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_hodu_proto_rawDesc = []byte{
|
||||
@ -572,39 +634,45 @@ var file_hodu_proto_rawDesc = []byte{
|
||||
0x75, 0x74, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x18,
|
||||
0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x12, 0x12, 0x0a,
|
||||
0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x44, 0x61, 0x74,
|
||||
0x61, 0x22, 0x95, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x20, 0x0a, 0x04,
|
||||
0x4b, 0x69, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x50, 0x41, 0x43,
|
||||
0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x52, 0x04, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x22,
|
||||
0x0a, 0x05, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e,
|
||||
0x52, 0x6f, 0x75, 0x74, 0x65, 0x44, 0x65, 0x73, 0x63, 0x48, 0x00, 0x52, 0x05, 0x52, 0x6f, 0x75,
|
||||
0x74, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x50, 0x65, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b,
|
||||
0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44, 0x65, 0x73, 0x63, 0x48, 0x00, 0x52, 0x04, 0x50,
|
||||
0x65, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28,
|
||||
0x0b, 0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x48, 0x00, 0x52, 0x04,
|
||||
0x44, 0x61, 0x74, 0x61, 0x42, 0x03, 0x0a, 0x01, 0x55, 0x2a, 0x5e, 0x0a, 0x0c, 0x52, 0x4f, 0x55,
|
||||
0x54, 0x45, 0x5f, 0x4f, 0x50, 0x54, 0x49, 0x4f, 0x4e, 0x12, 0x0a, 0x0a, 0x06, 0x55, 0x4e, 0x53,
|
||||
0x50, 0x45, 0x43, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x54, 0x43, 0x50, 0x10, 0x01, 0x12, 0x08,
|
||||
0x0a, 0x04, 0x54, 0x43, 0x50, 0x34, 0x10, 0x02, 0x12, 0x08, 0x0a, 0x04, 0x54, 0x43, 0x50, 0x36,
|
||||
0x10, 0x04, 0x12, 0x07, 0x0a, 0x03, 0x54, 0x54, 0x59, 0x10, 0x08, 0x12, 0x08, 0x0a, 0x04, 0x48,
|
||||
0x54, 0x54, 0x50, 0x10, 0x10, 0x12, 0x09, 0x0a, 0x05, 0x48, 0x54, 0x54, 0x50, 0x53, 0x10, 0x20,
|
||||
0x12, 0x07, 0x0a, 0x03, 0x53, 0x53, 0x48, 0x10, 0x40, 0x2a, 0xb5, 0x01, 0x0a, 0x0b, 0x50, 0x41,
|
||||
0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x12, 0x0c, 0x0a, 0x08, 0x52, 0x45, 0x53,
|
||||
0x45, 0x52, 0x56, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x52, 0x4f, 0x55, 0x54, 0x45,
|
||||
0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x52, 0x4f, 0x55, 0x54,
|
||||
0x45, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x10, 0x02, 0x12, 0x11, 0x0a, 0x0d, 0x52, 0x4f, 0x55, 0x54,
|
||||
0x45, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x45, 0x44, 0x10, 0x03, 0x12, 0x11, 0x0a, 0x0d, 0x52,
|
||||
0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x50, 0x45, 0x44, 0x10, 0x04, 0x12, 0x10,
|
||||
0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x45, 0x44, 0x10, 0x05,
|
||||
0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x50, 0x45, 0x44,
|
||||
0x10, 0x06, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x41, 0x42, 0x4f, 0x52, 0x54,
|
||||
0x45, 0x44, 0x10, 0x07, 0x12, 0x0c, 0x0a, 0x08, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x45, 0x4f, 0x46,
|
||||
0x10, 0x08, 0x12, 0x0d, 0x0a, 0x09, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x44, 0x41, 0x54, 0x41, 0x10,
|
||||
0x09, 0x32, 0x49, 0x0a, 0x04, 0x48, 0x6f, 0x64, 0x75, 0x12, 0x19, 0x0a, 0x07, 0x47, 0x65, 0x74,
|
||||
0x53, 0x65, 0x65, 0x64, 0x12, 0x05, 0x2e, 0x53, 0x65, 0x65, 0x64, 0x1a, 0x05, 0x2e, 0x53, 0x65,
|
||||
0x65, 0x64, 0x22, 0x00, 0x12, 0x26, 0x0a, 0x0c, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x53, 0x74,
|
||||
0x72, 0x65, 0x61, 0x6d, 0x12, 0x07, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x1a, 0x07, 0x2e,
|
||||
0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x42, 0x08, 0x5a, 0x06,
|
||||
0x2e, 0x2f, 0x68, 0x6f, 0x64, 0x75, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x61, 0x22, 0x20, 0x0a, 0x0a, 0x43, 0x6f, 0x6e, 0x6e, 0x4e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x12,
|
||||
0x12, 0x0a, 0x04, 0x54, 0x65, 0x78, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x54,
|
||||
0x65, 0x78, 0x74, 0x22, 0xbc, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x20,
|
||||
0x0a, 0x04, 0x4b, 0x69, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x50,
|
||||
0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x52, 0x04, 0x4b, 0x69, 0x6e, 0x64,
|
||||
0x12, 0x22, 0x0a, 0x05, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32,
|
||||
0x0a, 0x2e, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x44, 0x65, 0x73, 0x63, 0x48, 0x00, 0x52, 0x05, 0x52,
|
||||
0x6f, 0x75, 0x74, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x50, 0x65, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01,
|
||||
0x28, 0x0b, 0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44, 0x65, 0x73, 0x63, 0x48, 0x00, 0x52,
|
||||
0x04, 0x50, 0x65, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20,
|
||||
0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x48, 0x00,
|
||||
0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x12, 0x25, 0x0a, 0x06, 0x4e, 0x6f, 0x74, 0x69, 0x63, 0x65,
|
||||
0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x43, 0x6f, 0x6e, 0x6e, 0x4e, 0x6f, 0x74,
|
||||
0x69, 0x63, 0x65, 0x48, 0x00, 0x52, 0x06, 0x4e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x42, 0x03, 0x0a,
|
||||
0x01, 0x55, 0x2a, 0x5e, 0x0a, 0x0c, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x4f, 0x50, 0x54, 0x49,
|
||||
0x4f, 0x4e, 0x12, 0x0a, 0x0a, 0x06, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x10, 0x00, 0x12, 0x07,
|
||||
0x0a, 0x03, 0x54, 0x43, 0x50, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x54, 0x43, 0x50, 0x34, 0x10,
|
||||
0x02, 0x12, 0x08, 0x0a, 0x04, 0x54, 0x43, 0x50, 0x36, 0x10, 0x04, 0x12, 0x07, 0x0a, 0x03, 0x54,
|
||||
0x54, 0x59, 0x10, 0x08, 0x12, 0x08, 0x0a, 0x04, 0x48, 0x54, 0x54, 0x50, 0x10, 0x10, 0x12, 0x09,
|
||||
0x0a, 0x05, 0x48, 0x54, 0x54, 0x50, 0x53, 0x10, 0x20, 0x12, 0x07, 0x0a, 0x03, 0x53, 0x53, 0x48,
|
||||
0x10, 0x40, 0x2a, 0xc6, 0x01, 0x0a, 0x0b, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49,
|
||||
0x4e, 0x44, 0x12, 0x0c, 0x0a, 0x08, 0x52, 0x45, 0x53, 0x45, 0x52, 0x56, 0x45, 0x44, 0x10, 0x00,
|
||||
0x12, 0x0f, 0x0a, 0x0b, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x10,
|
||||
0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x10,
|
||||
0x02, 0x12, 0x11, 0x0a, 0x0d, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54,
|
||||
0x45, 0x44, 0x10, 0x03, 0x12, 0x11, 0x0a, 0x0d, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54,
|
||||
0x4f, 0x50, 0x50, 0x45, 0x44, 0x10, 0x04, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f,
|
||||
0x53, 0x54, 0x41, 0x52, 0x54, 0x45, 0x44, 0x10, 0x05, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45,
|
||||
0x52, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x50, 0x45, 0x44, 0x10, 0x06, 0x12, 0x10, 0x0a, 0x0c, 0x50,
|
||||
0x45, 0x45, 0x52, 0x5f, 0x41, 0x42, 0x4f, 0x52, 0x54, 0x45, 0x44, 0x10, 0x07, 0x12, 0x0c, 0x0a,
|
||||
0x08, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x45, 0x4f, 0x46, 0x10, 0x08, 0x12, 0x0d, 0x0a, 0x09, 0x50,
|
||||
0x45, 0x45, 0x52, 0x5f, 0x44, 0x41, 0x54, 0x41, 0x10, 0x09, 0x12, 0x0f, 0x0a, 0x0b, 0x43, 0x4f,
|
||||
0x4e, 0x4e, 0x5f, 0x4e, 0x4f, 0x54, 0x49, 0x43, 0x45, 0x10, 0x0a, 0x32, 0x49, 0x0a, 0x04, 0x48,
|
||||
0x6f, 0x64, 0x75, 0x12, 0x19, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x53, 0x65, 0x65, 0x64, 0x12, 0x05,
|
||||
0x2e, 0x53, 0x65, 0x65, 0x64, 0x1a, 0x05, 0x2e, 0x53, 0x65, 0x65, 0x64, 0x22, 0x00, 0x12, 0x26,
|
||||
0x0a, 0x0c, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x07,
|
||||
0x2e, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x1a, 0x07, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74,
|
||||
0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x42, 0x08, 0x5a, 0x06, 0x2e, 0x2f, 0x68, 0x6f, 0x64, 0x75,
|
||||
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@ -620,7 +688,7 @@ func file_hodu_proto_rawDescGZIP() []byte {
|
||||
}
|
||||
|
||||
var file_hodu_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
|
||||
var file_hodu_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
|
||||
var file_hodu_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
|
||||
var file_hodu_proto_goTypes = []any{
|
||||
(ROUTE_OPTION)(0), // 0: ROUTE_OPTION
|
||||
(PACKET_KIND)(0), // 1: PACKET_KIND
|
||||
@ -628,22 +696,24 @@ var file_hodu_proto_goTypes = []any{
|
||||
(*RouteDesc)(nil), // 3: RouteDesc
|
||||
(*PeerDesc)(nil), // 4: PeerDesc
|
||||
(*PeerData)(nil), // 5: PeerData
|
||||
(*Packet)(nil), // 6: Packet
|
||||
(*ConnNotice)(nil), // 6: ConnNotice
|
||||
(*Packet)(nil), // 7: Packet
|
||||
}
|
||||
var file_hodu_proto_depIdxs = []int32{
|
||||
1, // 0: Packet.Kind:type_name -> PACKET_KIND
|
||||
3, // 1: Packet.Route:type_name -> RouteDesc
|
||||
4, // 2: Packet.Peer:type_name -> PeerDesc
|
||||
5, // 3: Packet.Data:type_name -> PeerData
|
||||
2, // 4: Hodu.GetSeed:input_type -> Seed
|
||||
6, // 5: Hodu.PacketStream:input_type -> Packet
|
||||
2, // 6: Hodu.GetSeed:output_type -> Seed
|
||||
6, // 7: Hodu.PacketStream:output_type -> Packet
|
||||
6, // [6:8] is the sub-list for method output_type
|
||||
4, // [4:6] 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
|
||||
6, // 4: Packet.Notice:type_name -> ConnNotice
|
||||
2, // 5: Hodu.GetSeed:input_type -> Seed
|
||||
7, // 6: Hodu.PacketStream:input_type -> Packet
|
||||
2, // 7: Hodu.GetSeed:output_type -> Seed
|
||||
7, // 8: Hodu.PacketStream:output_type -> Packet
|
||||
7, // [7:9] is the sub-list for method output_type
|
||||
5, // [5:7] is the sub-list for method input_type
|
||||
5, // [5:5] is the sub-list for extension type_name
|
||||
5, // [5:5] is the sub-list for extension extendee
|
||||
0, // [0:5] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_hodu_proto_init() }
|
||||
@ -651,10 +721,11 @@ func file_hodu_proto_init() {
|
||||
if File_hodu_proto != nil {
|
||||
return
|
||||
}
|
||||
file_hodu_proto_msgTypes[4].OneofWrappers = []any{
|
||||
file_hodu_proto_msgTypes[5].OneofWrappers = []any{
|
||||
(*Packet_Route)(nil),
|
||||
(*Packet_Peer)(nil),
|
||||
(*Packet_Data)(nil),
|
||||
(*Packet_Notice)(nil),
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
@ -662,7 +733,7 @@ func file_hodu_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_hodu_proto_rawDesc,
|
||||
NumEnums: 2,
|
||||
NumMessages: 5,
|
||||
NumMessages: 6,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
|
@ -68,6 +68,10 @@ message PeerData {
|
||||
bytes Data = 3;
|
||||
};
|
||||
|
||||
message ConnNotice {
|
||||
string Text = 1;
|
||||
}
|
||||
|
||||
enum PACKET_KIND {
|
||||
RESERVED = 0; // not used
|
||||
ROUTE_START = 1;
|
||||
@ -79,6 +83,7 @@ enum PACKET_KIND {
|
||||
PEER_ABORTED = 7;
|
||||
PEER_EOF = 8;
|
||||
PEER_DATA = 9;
|
||||
CONN_NOTICE = 10;
|
||||
};
|
||||
|
||||
message Packet {
|
||||
@ -88,5 +93,6 @@ message Packet {
|
||||
RouteDesc Route = 2;
|
||||
PeerDesc Peer = 3;
|
||||
PeerData Data = 4;
|
||||
ConnNotice Notice = 5;
|
||||
};
|
||||
}
|
||||
|
@ -62,3 +62,7 @@ func MakePeerDataPacket(route_id RouteId, peer_id PeerId, data []byte) *Packet {
|
||||
return &Packet{Kind: PACKET_KIND_PEER_DATA,
|
||||
U: &Packet_Data{Data: &PeerData{RouteId: uint32(route_id), PeerId: uint32(peer_id), Data: data}}}
|
||||
}
|
||||
|
||||
func MakeConnNoticePacket(msg string) *Packet {
|
||||
return &Packet{Kind: PACKET_KIND_CONN_NOTICE, U: &Packet_Notice{Notice: &ConnNotice{Text: msg}}}
|
||||
}
|
||||
|
@ -85,6 +85,10 @@ type server_ctl_server_conns_id_routes_id_peers_id struct {
|
||||
server_ctl
|
||||
}
|
||||
|
||||
type server_ctl_server_conns_id_notices struct {
|
||||
server_ctl
|
||||
}
|
||||
|
||||
type server_ctl_stats struct {
|
||||
server_ctl
|
||||
}
|
||||
@ -476,7 +480,7 @@ func (ctl *server_ctl_server_conns_id_routes_id_peers) ServeHTTP(w http.Response
|
||||
|
||||
case http.MethodDelete:
|
||||
r.ReqStopAllServerPeerConns()
|
||||
status_code = WriteEmptyRespHeader(w, http.StatusNoContent)
|
||||
status_code = WriteEmptyRespHeader(w, http.StatusOK)
|
||||
|
||||
default:
|
||||
status_code = WriteEmptyRespHeader(w, http.StatusMethodNotAllowed)
|
||||
@ -546,11 +550,63 @@ oops:
|
||||
|
||||
// ------------------------------------
|
||||
|
||||
func (ctl *server_ctl_server_conns_id_notices) ServeHTTP(w http.ResponseWriter, req *http.Request) (int, error) {
|
||||
var s *Server
|
||||
var status_code int
|
||||
var conn_id string
|
||||
var cts *ServerConn
|
||||
var je *json.Encoder
|
||||
var err error
|
||||
|
||||
s = ctl.s
|
||||
je = json.NewEncoder(w)
|
||||
|
||||
conn_id = req.PathValue("conn_id")
|
||||
cts, err = s.FindServerConnByIdStr(conn_id)
|
||||
if err != nil {
|
||||
status_code = WriteJsonRespHeader(w, http.StatusNotFound)
|
||||
je.Encode(JsonErrmsg{Text: err.Error()})
|
||||
goto oops
|
||||
}
|
||||
|
||||
switch req.Method {
|
||||
case http.MethodPost:
|
||||
var noti json_in_notice
|
||||
|
||||
err = json.NewDecoder(req.Body).Decode(¬i)
|
||||
if err != nil {
|
||||
status_code = WriteEmptyRespHeader(w, http.StatusBadRequest)
|
||||
goto oops
|
||||
}
|
||||
|
||||
err = cts.pss.Send(MakeConnNoticePacket(noti.Text))
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to send conn_notice text to %s - %s", noti.Text, cts.RemoteAddr, err.Error())
|
||||
status_code = WriteJsonRespHeader(w, http.StatusInternalServerError)
|
||||
je.Encode(JsonErrmsg{Text: err.Error()})
|
||||
goto oops
|
||||
}
|
||||
|
||||
status_code = WriteJsonRespHeader(w, http.StatusOK)
|
||||
|
||||
default:
|
||||
status_code = WriteEmptyRespHeader(w, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
//done:
|
||||
return status_code, nil
|
||||
|
||||
oops:
|
||||
return status_code, err
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
|
||||
func (ctl *server_ctl_stats) ServeHTTP(w http.ResponseWriter, req *http.Request) (int, error) {
|
||||
var s *Server
|
||||
var status_code int
|
||||
var err error
|
||||
var je *json.Encoder
|
||||
var err error
|
||||
|
||||
s = ctl.s
|
||||
je = json.NewEncoder(w)
|
||||
|
13
server.go
13
server.go
@ -738,6 +738,17 @@ func (cts *ServerConn) receive_from_stream(wg *sync.WaitGroup) {
|
||||
// invalid event data
|
||||
cts.svr.log.Write(cts.sid, LOG_ERROR, "Invalid peer_data event from %s", cts.RemoteAddr)
|
||||
}
|
||||
|
||||
case PACKET_KIND_CONN_NOTICE:
|
||||
// the connection from the client to a peer has been established
|
||||
var x *Packet_Notice
|
||||
var ok bool
|
||||
x, ok = pkt.U.(*Packet_Notice)
|
||||
if ok {
|
||||
fmt.Printf ("CONN NOTICE [%s] from %s\n", x.Notice.Text, cts.RemoteAddr)
|
||||
} else {
|
||||
cts.svr.log.Write(cts.sid, LOG_ERROR, "Invalid conn_data event from %s", cts.RemoteAddr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1112,6 +1123,8 @@ func NewServer(ctx context.Context, name string, logger Logger, cfg *ServerConfi
|
||||
s.wrap_http_handler(&server_ctl_server_conns_id_routes_id_peers{server_ctl{s: &s, id: HS_ID_CTL}}))
|
||||
s.ctl_mux.Handle(s.cfg.CtlPrefix + "/_ctl/server-conns/{conn_id}/routes/{route_id}/peers/{peer_id}",
|
||||
s.wrap_http_handler(&server_ctl_server_conns_id_routes_id_peers_id{server_ctl{s: &s, id: HS_ID_CTL}}))
|
||||
s.ctl_mux.Handle(s.cfg.CtlPrefix + "/_ctl/server-conns/{conn_id}/notices",
|
||||
s.wrap_http_handler(&server_ctl_server_conns_id_notices{server_ctl{s: &s, id: HS_ID_CTL}}))
|
||||
s.ctl_mux.Handle(s.cfg.CtlPrefix + "/_ctl/stats",
|
||||
s.wrap_http_handler(&server_ctl_stats{server_ctl{s: &s, id: HS_ID_CTL}}))
|
||||
s.ctl_mux.Handle(s.cfg.CtlPrefix + "/_ctl/token",
|
||||
|
Loading…
x
Reference in New Issue
Block a user