rewrite event system for control socket

Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
Steffen Vogel
2022-01-14 13:46:22 +01:00
parent 8069c91af0
commit 2d1d719384
10 changed files with 407 additions and 298 deletions

View File

@@ -222,15 +222,8 @@ func (d *Daemon) SyncAllInterfaces() error {
} }
d.Events <- &pb.Event{ d.Events <- &pb.Event{
Type: "interface", Type: pb.Event_INTERFACE_REMOVED,
State: "removed", Interface: intf.Name(),
Event: &pb.Event_Intf{
Intf: &pb.InterfaceEvent{
Interface: &pb.Interface{
Name: i.Name(),
},
},
},
} }
} else { } else {
keepInterfaces = append(keepInterfaces, intf) keepInterfaces = append(keepInterfaces, intf)

View File

@@ -279,20 +279,10 @@ func (i *BaseInterface) onPeerAdded(p *wgtypes.Peer) {
i.peers[peer.PublicKey()] = peer i.peers[peer.PublicKey()] = peer
i.events <- &pb.Event{ i.events <- &pb.Event{
Type: "peer", Type: pb.Event_PEER_ADDED,
State: "added",
Event: &pb.Event_Intf{ Interface: i.Name(),
Intf: &pb.InterfaceEvent{ Peer: p.PublicKey[:],
Interface: &pb.Interface{
Name: i.Name(),
Peers: []*pb.Peer{
{
PublicKey: peer.PublicKey().Bytes(),
},
},
},
},
},
} }
} }
@@ -307,20 +297,10 @@ func (i *BaseInterface) onPeerRemoved(p *wgtypes.Peer) {
} }
i.events <- &pb.Event{ i.events <- &pb.Event{
Type: "peer", Type: pb.Event_PEER_REMOVED,
State: "removed",
Event: &pb.Event_Intf{ Interface: i.Name(),
Intf: &pb.InterfaceEvent{ Peer: p.PublicKey[:],
Interface: &pb.Interface{
Name: i.Name(),
Peers: []*pb.Peer{
{
PublicKey: peer.PublicKey().Bytes(),
},
},
},
},
},
} }
delete(i.peers, peer.PublicKey()) delete(i.peers, peer.PublicKey())
@@ -333,23 +313,6 @@ func (i *BaseInterface) onPeerModified(old, new *wgtypes.Peer, modified PeerModi
} else { } else {
i.logger.Error("Failed to find modified peer") i.logger.Error("Failed to find modified peer")
} }
i.events <- &pb.Event{
Type: "peer",
State: "modified",
Event: &pb.Event_Intf{
Intf: &pb.InterfaceEvent{
Interface: &pb.Interface{
Name: i.Name(),
Peers: []*pb.Peer{
{
PublicKey: peer.PublicKey().Bytes(),
},
},
},
},
},
}
} }
func (i *BaseInterface) AddPeer(pk wgtypes.Key) error { func (i *BaseInterface) AddPeer(pk wgtypes.Key) error {
@@ -418,15 +381,9 @@ func NewInterface(dev *wgtypes.Device, client *wgctrl.Client, backend signaling.
} }
i.events <- &pb.Event{ i.events <- &pb.Event{
Type: "interface", Type: pb.Event_INTERFACE_ADDED,
State: "added",
Event: &pb.Event_Intf{ Interface: i.Name(),
Intf: &pb.InterfaceEvent{
Interface: &pb.Interface{
Name: i.Name(),
},
},
},
} }
// We remove all peers here so that they get added by the following sync // We remove all peers here so that they get added by the following sync

View File

@@ -90,18 +90,18 @@ func (p *Peer) OnModified(new *wgtypes.Peer, modified PeerModifier) {
p.logger.Debug("New handshake", zap.Time("time", new.LastHandshakeTime)) p.logger.Debug("New handshake", zap.Time("time", new.LastHandshakeTime))
} }
p.server.BroadcastEvent(&pb.Event{ p.events <- &pb.Event{
Type: "peer", Type: pb.Event_PEER_MODIFIED,
State: "modified",
Event: &pb.Event_Peer{ Interface: p.Interface.Name(),
Peer: &pb.PeerEvent{ Peer: p.PublicKey().Bytes(),
Peer: &pb.Peer{
PublicKey: p.PublicKey().Bytes(), Event: &pb.Event_PeerModified{
LastHandshake: pb.Time(new.LastHandshakeTime), PeerModified: &pb.PeerModifiedEvent{
Modified: uint32(modified),
}, },
}, },
}, }
})
} }
func (p *Peer) onCandidate(c ice.Candidate) { func (p *Peer) onCandidate(c ice.Candidate) {
@@ -125,23 +125,18 @@ func (p *Peer) onConnectionStateChange(state ice.ConnectionState) {
p.logger.Info("Connection state changed", zap.String("state", stateLower)) p.logger.Info("Connection state changed", zap.String("state", stateLower))
p.server.BroadcastEvent(&pb.Event{ p.events <- &pb.Event{
Type: "state", Type: pb.Event_PEER_CONNECTION_STATE_CHANGED,
State: "changed",
Event: &pb.Event_Intf{ Interface: p.Interface.Name(),
Intf: &pb.InterfaceEvent{ Peer: p.PublicKey().Bytes(),
Interface: &pb.Interface{
Name: p.Interface.Name(), Event: &pb.Event_PeerConnectionStateChange{
Peers: []*pb.Peer{ PeerConnectionStateChange: &pb.PeerConnectionStateChangeEvent{
{ NewState: pb.NewConnectionState(state),
PublicKey: p.PublicKey().Bytes(),
State: pb.ConnectionState(state),
}, },
}, },
}, }
},
},
})
if state == ice.ConnectionStateFailed { if state == ice.ConnectionStateFailed {
go p.restartLocal() go p.restartLocal()

View File

@@ -1,31 +1,30 @@
package pb package pb
import ( import (
"strings"
"go.uber.org/zap" "go.uber.org/zap"
"riasc.eu/wice/pkg/crypto"
) )
func (e *Event) Log(l *zap.Logger, msg string, fields ...zap.Field) { func (e *Event) Log(l *zap.Logger, msg string, fields ...zap.Field) {
fields = append(fields, fields = append(fields,
zap.String("type", e.Type), zap.String("type", strings.ToLower(e.Type.String())),
zap.String("state", e.State),
zap.Any("event", e.Event), zap.Any("event", e.Event),
) )
if e.Interface != "" {
fields = append(fields, zap.String("interface", e.Interface))
}
if e.Peer != nil {
pk := (*crypto.Key)(e.Peer)
fields = append(fields, zap.Any("peer", pk))
}
if e.Time != nil { if e.Time != nil {
fields = append(fields, zap.Any("time", e.Time.Time())) fields = append(fields, zap.Time("time", e.Time.Time()))
} }
l.Info(msg, fields...) l.Info(msg, fields...)
} }
func (e *Event) Match(o *Event) bool {
if e.Type != o.Type {
return false
}
if e.State != o.State {
return false
}
return true
}

View File

@@ -20,46 +20,110 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
) )
type BackendEvent_Type int32 type Event_Type int32
const ( const (
BackendEvent_READY BackendEvent_Type = 0 Event_BACKEND_READY Event_Type = 0
Event_PEER_ADDED Event_Type = 20
Event_PEER_REMOVED Event_Type = 21
Event_PEER_MODIFIED Event_Type = 22
Event_PEER_CONNECTION_STATE_CHANGED Event_Type = 23
Event_INTERFACE_ADDED Event_Type = 30
Event_INTERFACE_REMOVED Event_Type = 31
) )
// Enum value maps for BackendEvent_Type. // Enum value maps for Event_Type.
var ( var (
BackendEvent_Type_name = map[int32]string{ Event_Type_name = map[int32]string{
0: "READY", 0: "BACKEND_READY",
20: "PEER_ADDED",
21: "PEER_REMOVED",
22: "PEER_MODIFIED",
23: "PEER_CONNECTION_STATE_CHANGED",
30: "INTERFACE_ADDED",
31: "INTERFACE_REMOVED",
} }
BackendEvent_Type_value = map[string]int32{ Event_Type_value = map[string]int32{
"READY": 0, "BACKEND_READY": 0,
"PEER_ADDED": 20,
"PEER_REMOVED": 21,
"PEER_MODIFIED": 22,
"PEER_CONNECTION_STATE_CHANGED": 23,
"INTERFACE_ADDED": 30,
"INTERFACE_REMOVED": 31,
} }
) )
func (x BackendEvent_Type) Enum() *BackendEvent_Type { func (x Event_Type) Enum() *Event_Type {
p := new(BackendEvent_Type) p := new(Event_Type)
*p = x *p = x
return p return p
} }
func (x BackendEvent_Type) String() string { func (x Event_Type) String() string {
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
} }
func (BackendEvent_Type) Descriptor() protoreflect.EnumDescriptor { func (Event_Type) Descriptor() protoreflect.EnumDescriptor {
return file_event_proto_enumTypes[0].Descriptor() return file_event_proto_enumTypes[0].Descriptor()
} }
func (BackendEvent_Type) Type() protoreflect.EnumType { func (Event_Type) Type() protoreflect.EnumType {
return &file_event_proto_enumTypes[0] return &file_event_proto_enumTypes[0]
} }
func (x BackendEvent_Type) Number() protoreflect.EnumNumber { func (x Event_Type) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x) return protoreflect.EnumNumber(x)
} }
// Deprecated: Use BackendEvent_Type.Descriptor instead. // Deprecated: Use Event_Type.Descriptor instead.
func (BackendEvent_Type) EnumDescriptor() ([]byte, []int) { func (Event_Type) EnumDescriptor() ([]byte, []int) {
return file_event_proto_rawDescGZIP(), []int{0, 0}
}
type BackendReadyEvent_Type int32
const (
BackendReadyEvent_P2P BackendReadyEvent_Type = 0
BackendReadyEvent_K8S BackendReadyEvent_Type = 1
)
// Enum value maps for BackendReadyEvent_Type.
var (
BackendReadyEvent_Type_name = map[int32]string{
0: "P2P",
1: "K8S",
}
BackendReadyEvent_Type_value = map[string]int32{
"P2P": 0,
"K8S": 1,
}
)
func (x BackendReadyEvent_Type) Enum() *BackendReadyEvent_Type {
p := new(BackendReadyEvent_Type)
*p = x
return p
}
func (x BackendReadyEvent_Type) String() string {
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
func (BackendReadyEvent_Type) Descriptor() protoreflect.EnumDescriptor {
return file_event_proto_enumTypes[1].Descriptor()
}
func (BackendReadyEvent_Type) Type() protoreflect.EnumType {
return &file_event_proto_enumTypes[1]
}
func (x BackendReadyEvent_Type) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x)
}
// Deprecated: Use BackendReadyEvent_Type.Descriptor instead.
func (BackendReadyEvent_Type) EnumDescriptor() ([]byte, []int) {
return file_event_proto_rawDescGZIP(), []int{3, 0} return file_event_proto_rawDescGZIP(), []int{3, 0}
} }
@@ -68,13 +132,15 @@ type Event struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Time *Timestamp `protobuf:"bytes,1,opt,name=time,proto3" json:"time,omitempty"` Type Event_Type `protobuf:"varint,1,opt,name=type,proto3,enum=Event_Type" json:"type,omitempty"`
Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` Time *Timestamp `protobuf:"bytes,2,opt,name=time,proto3" json:"time,omitempty"`
State string `protobuf:"bytes,3,opt,name=state,proto3" json:"state,omitempty"` // Originator
Peer []byte `protobuf:"bytes,3,opt,name=peer,proto3" json:"peer,omitempty"`
Interface string `protobuf:"bytes,4,opt,name=interface,proto3" json:"interface,omitempty"`
// Types that are assignable to Event: // Types that are assignable to Event:
// *Event_Peer // *Event_PeerModified
// *Event_Intf // *Event_PeerConnectionStateChange
// *Event_Backend // *Event_BackendReady
Event isEvent_Event `protobuf_oneof:"event"` Event isEvent_Event `protobuf_oneof:"event"`
} }
@@ -110,6 +176,13 @@ func (*Event) Descriptor() ([]byte, []int) {
return file_event_proto_rawDescGZIP(), []int{0} return file_event_proto_rawDescGZIP(), []int{0}
} }
func (x *Event) GetType() Event_Type {
if x != nil {
return x.Type
}
return Event_BACKEND_READY
}
func (x *Event) GetTime() *Timestamp { func (x *Event) GetTime() *Timestamp {
if x != nil { if x != nil {
return x.Time return x.Time
@@ -117,16 +190,16 @@ func (x *Event) GetTime() *Timestamp {
return nil return nil
} }
func (x *Event) GetType() string { func (x *Event) GetPeer() []byte {
if x != nil { if x != nil {
return x.Type return x.Peer
} }
return "" return nil
} }
func (x *Event) GetState() string { func (x *Event) GetInterface() string {
if x != nil { if x != nil {
return x.State return x.Interface
} }
return "" return ""
} }
@@ -138,23 +211,23 @@ func (m *Event) GetEvent() isEvent_Event {
return nil return nil
} }
func (x *Event) GetPeer() *PeerEvent { func (x *Event) GetPeerModified() *PeerModifiedEvent {
if x, ok := x.GetEvent().(*Event_Peer); ok { if x, ok := x.GetEvent().(*Event_PeerModified); ok {
return x.Peer return x.PeerModified
} }
return nil return nil
} }
func (x *Event) GetIntf() *InterfaceEvent { func (x *Event) GetPeerConnectionStateChange() *PeerConnectionStateChangeEvent {
if x, ok := x.GetEvent().(*Event_Intf); ok { if x, ok := x.GetEvent().(*Event_PeerConnectionStateChange); ok {
return x.Intf return x.PeerConnectionStateChange
} }
return nil return nil
} }
func (x *Event) GetBackend() *BackendEvent { func (x *Event) GetBackendReady() *BackendReadyEvent {
if x, ok := x.GetEvent().(*Event_Backend); ok { if x, ok := x.GetEvent().(*Event_BackendReady); ok {
return x.Backend return x.BackendReady
} }
return nil return nil
} }
@@ -163,35 +236,34 @@ type isEvent_Event interface {
isEvent_Event() isEvent_Event()
} }
type Event_Peer struct { type Event_PeerModified struct {
Peer *PeerEvent `protobuf:"bytes,10,opt,name=peer,proto3,oneof"` PeerModified *PeerModifiedEvent `protobuf:"bytes,10,opt,name=peer_modified,json=peerModified,proto3,oneof"`
} }
type Event_Intf struct { type Event_PeerConnectionStateChange struct {
Intf *InterfaceEvent `protobuf:"bytes,11,opt,name=intf,proto3,oneof"` PeerConnectionStateChange *PeerConnectionStateChangeEvent `protobuf:"bytes,11,opt,name=peer_connection_state_change,json=peerConnectionStateChange,proto3,oneof"`
} }
type Event_Backend struct { type Event_BackendReady struct {
Backend *BackendEvent `protobuf:"bytes,12,opt,name=backend,proto3,oneof"` BackendReady *BackendReadyEvent `protobuf:"bytes,30,opt,name=backend_ready,json=backendReady,proto3,oneof"`
} }
func (*Event_Peer) isEvent_Event() {} func (*Event_PeerModified) isEvent_Event() {}
func (*Event_Intf) isEvent_Event() {} func (*Event_PeerConnectionStateChange) isEvent_Event() {}
func (*Event_Backend) isEvent_Event() {} func (*Event_BackendReady) isEvent_Event() {}
type PeerEvent struct { type PeerModifiedEvent struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Peer *Peer `protobuf:"bytes,1,opt,name=peer,proto3" json:"peer,omitempty"` Modified uint32 `protobuf:"varint,1,opt,name=modified,proto3" json:"modified,omitempty"`
Modified []string `protobuf:"bytes,2,rep,name=modified,proto3" json:"modified,omitempty"`
} }
func (x *PeerEvent) Reset() { func (x *PeerModifiedEvent) Reset() {
*x = PeerEvent{} *x = PeerModifiedEvent{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_event_proto_msgTypes[1] mi := &file_event_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@@ -199,13 +271,13 @@ func (x *PeerEvent) Reset() {
} }
} }
func (x *PeerEvent) String() string { func (x *PeerModifiedEvent) String() string {
return protoimpl.X.MessageStringOf(x) return protoimpl.X.MessageStringOf(x)
} }
func (*PeerEvent) ProtoMessage() {} func (*PeerModifiedEvent) ProtoMessage() {}
func (x *PeerEvent) ProtoReflect() protoreflect.Message { func (x *PeerModifiedEvent) ProtoReflect() protoreflect.Message {
mi := &file_event_proto_msgTypes[1] mi := &file_event_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@@ -217,35 +289,28 @@ func (x *PeerEvent) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x) return mi.MessageOf(x)
} }
// Deprecated: Use PeerEvent.ProtoReflect.Descriptor instead. // Deprecated: Use PeerModifiedEvent.ProtoReflect.Descriptor instead.
func (*PeerEvent) Descriptor() ([]byte, []int) { func (*PeerModifiedEvent) Descriptor() ([]byte, []int) {
return file_event_proto_rawDescGZIP(), []int{1} return file_event_proto_rawDescGZIP(), []int{1}
} }
func (x *PeerEvent) GetPeer() *Peer { func (x *PeerModifiedEvent) GetModified() uint32 {
if x != nil {
return x.Peer
}
return nil
}
func (x *PeerEvent) GetModified() []string {
if x != nil { if x != nil {
return x.Modified return x.Modified
} }
return nil return 0
} }
type InterfaceEvent struct { type PeerConnectionStateChangeEvent struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Interface *Interface `protobuf:"bytes,1,opt,name=interface,proto3" json:"interface,omitempty"` NewState ConnectionState `protobuf:"varint,3,opt,name=new_state,json=newState,proto3,enum=ConnectionState" json:"new_state,omitempty"`
} }
func (x *InterfaceEvent) Reset() { func (x *PeerConnectionStateChangeEvent) Reset() {
*x = InterfaceEvent{} *x = PeerConnectionStateChangeEvent{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_event_proto_msgTypes[2] mi := &file_event_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@@ -253,13 +318,13 @@ func (x *InterfaceEvent) Reset() {
} }
} }
func (x *InterfaceEvent) String() string { func (x *PeerConnectionStateChangeEvent) String() string {
return protoimpl.X.MessageStringOf(x) return protoimpl.X.MessageStringOf(x)
} }
func (*InterfaceEvent) ProtoMessage() {} func (*PeerConnectionStateChangeEvent) ProtoMessage() {}
func (x *InterfaceEvent) ProtoReflect() protoreflect.Message { func (x *PeerConnectionStateChangeEvent) ProtoReflect() protoreflect.Message {
mi := &file_event_proto_msgTypes[2] mi := &file_event_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@@ -271,30 +336,30 @@ func (x *InterfaceEvent) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x) return mi.MessageOf(x)
} }
// Deprecated: Use InterfaceEvent.ProtoReflect.Descriptor instead. // Deprecated: Use PeerConnectionStateChangeEvent.ProtoReflect.Descriptor instead.
func (*InterfaceEvent) Descriptor() ([]byte, []int) { func (*PeerConnectionStateChangeEvent) Descriptor() ([]byte, []int) {
return file_event_proto_rawDescGZIP(), []int{2} return file_event_proto_rawDescGZIP(), []int{2}
} }
func (x *InterfaceEvent) GetInterface() *Interface { func (x *PeerConnectionStateChangeEvent) GetNewState() ConnectionState {
if x != nil { if x != nil {
return x.Interface return x.NewState
} }
return nil return ConnectionState_NEW
} }
type BackendEvent struct { type BackendReadyEvent struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Type BackendEvent_Type `protobuf:"varint,1,opt,name=type,proto3,enum=BackendEvent_Type" json:"type,omitempty"` Type BackendReadyEvent_Type `protobuf:"varint,1,opt,name=type,proto3,enum=BackendReadyEvent_Type" json:"type,omitempty"`
Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
ListenAddresses []string `protobuf:"bytes,3,rep,name=listen_addresses,json=listenAddresses,proto3" json:"listen_addresses,omitempty"` ListenAddresses []string `protobuf:"bytes,3,rep,name=listen_addresses,json=listenAddresses,proto3" json:"listen_addresses,omitempty"`
} }
func (x *BackendEvent) Reset() { func (x *BackendReadyEvent) Reset() {
*x = BackendEvent{} *x = BackendReadyEvent{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_event_proto_msgTypes[3] mi := &file_event_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@@ -302,13 +367,13 @@ func (x *BackendEvent) Reset() {
} }
} }
func (x *BackendEvent) String() string { func (x *BackendReadyEvent) String() string {
return protoimpl.X.MessageStringOf(x) return protoimpl.X.MessageStringOf(x)
} }
func (*BackendEvent) ProtoMessage() {} func (*BackendReadyEvent) ProtoMessage() {}
func (x *BackendEvent) ProtoReflect() protoreflect.Message { func (x *BackendReadyEvent) ProtoReflect() protoreflect.Message {
mi := &file_event_proto_msgTypes[3] mi := &file_event_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@@ -320,26 +385,26 @@ func (x *BackendEvent) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x) return mi.MessageOf(x)
} }
// Deprecated: Use BackendEvent.ProtoReflect.Descriptor instead. // Deprecated: Use BackendReadyEvent.ProtoReflect.Descriptor instead.
func (*BackendEvent) Descriptor() ([]byte, []int) { func (*BackendReadyEvent) Descriptor() ([]byte, []int) {
return file_event_proto_rawDescGZIP(), []int{3} return file_event_proto_rawDescGZIP(), []int{3}
} }
func (x *BackendEvent) GetType() BackendEvent_Type { func (x *BackendReadyEvent) GetType() BackendReadyEvent_Type {
if x != nil { if x != nil {
return x.Type return x.Type
} }
return BackendEvent_READY return BackendReadyEvent_P2P
} }
func (x *BackendEvent) GetId() string { func (x *BackendReadyEvent) GetId() string {
if x != nil { if x != nil {
return x.Id return x.Id
} }
return "" return ""
} }
func (x *BackendEvent) GetListenAddresses() []string { func (x *BackendReadyEvent) GetListenAddresses() []string {
if x != nil { if x != nil {
return x.ListenAddresses return x.ListenAddresses
} }
@@ -350,40 +415,59 @@ var File_event_proto protoreflect.FileDescriptor
var file_event_proto_rawDesc = []byte{ var file_event_proto_rawDesc = []byte{
0x0a, 0x0b, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0c, 0x63, 0x0a, 0x0b, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0c, 0x63,
0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0a, 0x70, 0x65, 0x65, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xfd, 0x03, 0x0a, 0x05,
0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1f, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20,
0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xce, 0x01, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x01, 0x28, 0x0e, 0x32, 0x0b, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x54, 0x79, 0x70, 0x65,
0x6e, 0x74, 0x12, 0x1e, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02,
0x32, 0x0a, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x04, 0x74, 0x69, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70,
0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x65, 0x65, 0x72, 0x18, 0x03,
0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x70, 0x65, 0x65, 0x72, 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x6e,
0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x20, 0x0a, 0x04, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x69,
0x70, 0x65, 0x65, 0x72, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x50, 0x65, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x12, 0x39, 0x0a, 0x0d, 0x70, 0x65, 0x65, 0x72,
0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x04, 0x70, 0x65, 0x65, 0x72, 0x12, 0x25, 0x5f, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x0a, 0x04, 0x69, 0x6e, 0x74, 0x66, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x49, 0x12, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x45, 0x76,
0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x65, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x0c, 0x70, 0x65, 0x65, 0x72, 0x4d, 0x6f, 0x64, 0x69, 0x66,
0x04, 0x69, 0x6e, 0x74, 0x66, 0x12, 0x29, 0x0a, 0x07, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x69, 0x65, 0x64, 0x12, 0x62, 0x0a, 0x1c, 0x70, 0x65, 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x6e, 0x6e,
0x18, 0x0c, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x5f, 0x63, 0x68, 0x61,
0x45, 0x76, 0x65, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x07, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x6e, 0x67, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x50, 0x65, 0x65, 0x72,
0x42, 0x07, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x22, 0x42, 0x0a, 0x09, 0x50, 0x65, 0x65, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x43,
0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x19, 0x0a, 0x04, 0x70, 0x65, 0x65, 0x72, 0x18, 0x01, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x19, 0x70, 0x65,
0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x52, 0x04, 0x70, 0x65, 0x65, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74,
0x72, 0x12, 0x1a, 0x0a, 0x08, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x18, 0x02, 0x20, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x39, 0x0a, 0x0d, 0x62, 0x61, 0x63, 0x6b, 0x65,
0x03, 0x28, 0x09, 0x52, 0x08, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x22, 0x3a, 0x0a, 0x6e, 0x64, 0x5f, 0x72, 0x65, 0x61, 0x64, 0x79, 0x18, 0x1e, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12,
0x0e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x61, 0x64, 0x79, 0x45, 0x76, 0x65,
0x28, 0x0a, 0x09, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x0c, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x61,
0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x52, 0x09, 0x64, 0x79, 0x22, 0x9d, 0x01, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x11, 0x0a, 0x0d, 0x42,
0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x22, 0x84, 0x01, 0x0a, 0x0c, 0x42, 0x61, 0x41, 0x43, 0x4b, 0x45, 0x4e, 0x44, 0x5f, 0x52, 0x45, 0x41, 0x44, 0x59, 0x10, 0x00, 0x12, 0x0e,
0x63, 0x6b, 0x65, 0x6e, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x26, 0x0a, 0x04, 0x74, 0x79, 0x0a, 0x0a, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x41, 0x44, 0x44, 0x45, 0x44, 0x10, 0x14, 0x12, 0x10,
0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x12, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x52, 0x45, 0x4d, 0x4f, 0x56, 0x45, 0x44, 0x10, 0x15,
0x6e, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x12, 0x11, 0x0a, 0x0d, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x4d, 0x4f, 0x44, 0x49, 0x46, 0x49, 0x45,
0x70, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x44, 0x10, 0x16, 0x12, 0x21, 0x0a, 0x1d, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x43, 0x4f, 0x4e, 0x4e,
0x69, 0x64, 0x12, 0x29, 0x0a, 0x10, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x5f, 0x61, 0x64, 0x64, 0x45, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x45, 0x5f, 0x43, 0x48, 0x41,
0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0f, 0x6c, 0x69, 0x4e, 0x47, 0x45, 0x44, 0x10, 0x17, 0x12, 0x13, 0x0a, 0x0f, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x46,
0x73, 0x74, 0x65, 0x6e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x22, 0x11, 0x0a, 0x41, 0x43, 0x45, 0x5f, 0x41, 0x44, 0x44, 0x45, 0x44, 0x10, 0x1e, 0x12, 0x15, 0x0a, 0x11, 0x49,
0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x09, 0x0a, 0x05, 0x52, 0x45, 0x41, 0x44, 0x59, 0x10, 0x00, 0x4e, 0x54, 0x45, 0x52, 0x46, 0x41, 0x43, 0x45, 0x5f, 0x52, 0x45, 0x4d, 0x4f, 0x56, 0x45, 0x44,
0x42, 0x16, 0x5a, 0x14, 0x72, 0x69, 0x61, 0x73, 0x63, 0x2e, 0x65, 0x75, 0x2f, 0x77, 0x69, 0x63, 0x10, 0x1f, 0x42, 0x07, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x22, 0x2f, 0x0a, 0x11, 0x50,
0x65, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x65, 0x65, 0x72, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74,
0x12, 0x1a, 0x0a, 0x08, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01,
0x28, 0x0d, 0x52, 0x08, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x22, 0x4f, 0x0a, 0x1e,
0x50, 0x65, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74,
0x61, 0x74, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x2d,
0x0a, 0x09, 0x6e, 0x65, 0x77, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28,
0x0e, 0x32, 0x10, 0x2e, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74,
0x61, 0x74, 0x65, 0x52, 0x08, 0x6e, 0x65, 0x77, 0x53, 0x74, 0x61, 0x74, 0x65, 0x22, 0x95, 0x01,
0x0a, 0x11, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x61, 0x64, 0x79, 0x45, 0x76,
0x65, 0x6e, 0x74, 0x12, 0x2b, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
0x0e, 0x32, 0x17, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x61, 0x64, 0x79,
0x45, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65,
0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64,
0x12, 0x29, 0x0a, 0x10, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65,
0x73, 0x73, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0f, 0x6c, 0x69, 0x73, 0x74,
0x65, 0x6e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x22, 0x18, 0x0a, 0x04, 0x54,
0x79, 0x70, 0x65, 0x12, 0x07, 0x0a, 0x03, 0x50, 0x32, 0x50, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03,
0x4b, 0x38, 0x53, 0x10, 0x01, 0x42, 0x16, 0x5a, 0x14, 0x72, 0x69, 0x61, 0x73, 0x63, 0x2e, 0x65,
0x75, 0x2f, 0x77, 0x69, 0x63, 0x65, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
@@ -398,26 +482,26 @@ func file_event_proto_rawDescGZIP() []byte {
return file_event_proto_rawDescData return file_event_proto_rawDescData
} }
var file_event_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_event_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
var file_event_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_event_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
var file_event_proto_goTypes = []interface{}{ var file_event_proto_goTypes = []interface{}{
(BackendEvent_Type)(0), // 0: BackendEvent.Type (Event_Type)(0), // 0: Event.Type
(*Event)(nil), // 1: Event (BackendReadyEvent_Type)(0), // 1: BackendReadyEvent.Type
(*PeerEvent)(nil), // 2: PeerEvent (*Event)(nil), // 2: Event
(*InterfaceEvent)(nil), // 3: InterfaceEvent (*PeerModifiedEvent)(nil), // 3: PeerModifiedEvent
(*BackendEvent)(nil), // 4: BackendEvent (*PeerConnectionStateChangeEvent)(nil), // 4: PeerConnectionStateChangeEvent
(*Timestamp)(nil), // 5: Timestamp (*BackendReadyEvent)(nil), // 5: BackendReadyEvent
(*Peer)(nil), // 6: Peer (*Timestamp)(nil), // 6: Timestamp
(*Interface)(nil), // 7: Interface (ConnectionState)(0), // 7: ConnectionState
} }
var file_event_proto_depIdxs = []int32{ var file_event_proto_depIdxs = []int32{
5, // 0: Event.time:type_name -> Timestamp 0, // 0: Event.type:type_name -> Event.Type
2, // 1: Event.peer:type_name -> PeerEvent 6, // 1: Event.time:type_name -> Timestamp
3, // 2: Event.intf:type_name -> InterfaceEvent 3, // 2: Event.peer_modified:type_name -> PeerModifiedEvent
4, // 3: Event.backend:type_name -> BackendEvent 4, // 3: Event.peer_connection_state_change:type_name -> PeerConnectionStateChangeEvent
6, // 4: PeerEvent.peer:type_name -> Peer 5, // 4: Event.backend_ready:type_name -> BackendReadyEvent
7, // 5: InterfaceEvent.interface:type_name -> Interface 7, // 5: PeerConnectionStateChangeEvent.new_state:type_name -> ConnectionState
0, // 6: BackendEvent.type:type_name -> BackendEvent.Type 1, // 6: BackendReadyEvent.type:type_name -> BackendReadyEvent.Type
7, // [7:7] is the sub-list for method output_type 7, // [7:7] is the sub-list for method output_type
7, // [7:7] is the sub-list for method input_type 7, // [7:7] is the sub-list for method input_type
7, // [7:7] is the sub-list for extension type_name 7, // [7:7] is the sub-list for extension type_name
@@ -431,8 +515,6 @@ func file_event_proto_init() {
return return
} }
file_common_proto_init() file_common_proto_init()
file_peer_proto_init()
file_interface_proto_init()
if !protoimpl.UnsafeEnabled { if !protoimpl.UnsafeEnabled {
file_event_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { file_event_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Event); i { switch v := v.(*Event); i {
@@ -447,7 +529,7 @@ func file_event_proto_init() {
} }
} }
file_event_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { file_event_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PeerEvent); i { switch v := v.(*PeerModifiedEvent); i {
case 0: case 0:
return &v.state return &v.state
case 1: case 1:
@@ -459,7 +541,7 @@ func file_event_proto_init() {
} }
} }
file_event_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { file_event_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*InterfaceEvent); i { switch v := v.(*PeerConnectionStateChangeEvent); i {
case 0: case 0:
return &v.state return &v.state
case 1: case 1:
@@ -471,7 +553,7 @@ func file_event_proto_init() {
} }
} }
file_event_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { file_event_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*BackendEvent); i { switch v := v.(*BackendReadyEvent); i {
case 0: case 0:
return &v.state return &v.state
case 1: case 1:
@@ -484,16 +566,16 @@ func file_event_proto_init() {
} }
} }
file_event_proto_msgTypes[0].OneofWrappers = []interface{}{ file_event_proto_msgTypes[0].OneofWrappers = []interface{}{
(*Event_Peer)(nil), (*Event_PeerModified)(nil),
(*Event_Intf)(nil), (*Event_PeerConnectionStateChange)(nil),
(*Event_Backend)(nil), (*Event_BackendReady)(nil),
} }
type x struct{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{ File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_event_proto_rawDesc, RawDescriptor: file_event_proto_rawDesc,
NumEnums: 1, NumEnums: 2,
NumMessages: 4, NumMessages: 4,
NumExtensions: 0, NumExtensions: 0,
NumServices: 0, NumServices: 0,

View File

@@ -3,34 +3,47 @@ syntax = "proto3";
option go_package = "riasc.eu/wice/pkg/pb"; option go_package = "riasc.eu/wice/pkg/pb";
import "common.proto"; import "common.proto";
import "peer.proto";
import "interface.proto";
message Event { message Event {
Timestamp time = 1; enum Type {
string type = 2; BACKEND_READY = 0;
string state = 3;
PEER_ADDED = 20;
PEER_REMOVED = 21;
PEER_MODIFIED = 22;
PEER_CONNECTION_STATE_CHANGED = 23;
INTERFACE_ADDED = 30;
INTERFACE_REMOVED = 31;
}
Type type = 1;
Timestamp time = 2;
// Originator
bytes peer = 3;
string interface = 4;
oneof event { oneof event {
PeerEvent peer = 10; PeerModifiedEvent peer_modified = 10;
InterfaceEvent intf = 11; PeerConnectionStateChangeEvent peer_connection_state_change = 11;
BackendEvent backend = 12;
BackendReadyEvent backend_ready = 30;
} }
} }
message PeerEvent { message PeerModifiedEvent {
Peer peer = 1; uint32 modified = 1;
repeated string modified = 2;
} }
message InterfaceEvent { message PeerConnectionStateChangeEvent {
Interface interface = 1; ConnectionState new_state = 3;
} }
message BackendEvent { message BackendReadyEvent {
enum Type { enum Type {
READY = 0; P2P = 0;
K8S = 1;
} }
Type type = 1; Type type = 1;

View File

@@ -121,8 +121,12 @@ func NewBackend(uri *url.URL, events chan *pb.Event) (signaling.Backend, error)
b.logger.Debug("Started batched updates") b.logger.Debug("Started batched updates")
b.events <- &pb.Event{ b.events <- &pb.Event{
Type: "backend", Type: pb.Event_BACKEND_READY,
State: "ready", Event: &pb.Event_BackendReady{
BackendReady: &pb.BackendReadyEvent{
Type: pb.BackendReadyEvent_K8S,
},
},
} }
return &b, nil return &b, nil

View File

@@ -196,10 +196,10 @@ func NewBackend(uri *url.URL, events chan *pb.Event) (signaling.Backend, error)
} }
b.events <- &pb.Event{ b.events <- &pb.Event{
Type: "backend", Type: pb.Event_BACKEND_READY,
State: "ready", Event: &pb.Event_BackendReady{
Event: &pb.Event_Backend{ BackendReady: &pb.BackendReadyEvent{
Backend: &pb.BackendEvent{ Type: pb.BackendReadyEvent_P2P,
Id: b.host.ID().String(), Id: b.host.ID().String(),
ListenAddresses: as, ListenAddresses: as,
}, },

View File

@@ -1,16 +1,20 @@
package socket package socket
import ( import (
"bytes"
"context" "context"
"fmt" "fmt"
"io" "io"
"os" "os"
"sync"
"time" "time"
"github.com/pion/ice/v2"
"go.uber.org/zap" "go.uber.org/zap"
"google.golang.org/grpc" "google.golang.org/grpc"
ginsecure "google.golang.org/grpc/credentials/insecure" ginsecure "google.golang.org/grpc/credentials/insecure"
"riasc.eu/wice/pkg/crypto" "riasc.eu/wice/pkg/crypto"
"riasc.eu/wice/pkg/intf"
"riasc.eu/wice/pkg/pb" "riasc.eu/wice/pkg/pb"
) )
@@ -21,6 +25,10 @@ type Client struct {
grpc *grpc.ClientConn grpc *grpc.ClientConn
logger *zap.Logger logger *zap.Logger
connectionStates map[crypto.Key]ice.ConnectionState
connectionStatesLock sync.Mutex
connectionStatesCond *sync.Cond
Events chan *pb.Event Events chan *pb.Event
} }
@@ -63,7 +71,11 @@ func Connect(path string) (*Client, error) {
grpc: conn, grpc: conn,
logger: logger, logger: logger,
Events: make(chan *pb.Event, 100), Events: make(chan *pb.Event, 100),
connectionStates: make(map[crypto.Key]ice.ConnectionState),
} }
client.connectionStatesCond = sync.NewCond(&client.connectionStatesLock)
go client.streamEvents()
rerr, err := client.UnWait(context.Background(), &pb.UnWaitParams{}) rerr, err := client.UnWait(context.Background(), &pb.UnWaitParams{})
if err != nil { if err != nil {
@@ -72,8 +84,6 @@ func Connect(path string) (*Client, error) {
return nil, fmt.Errorf("received RPC error: %w", rerr) return nil, fmt.Errorf("received RPC error: %w", rerr)
} }
go client.streamEvents()
return client, nil return client, nil
} }
@@ -84,44 +94,82 @@ func (c *Client) Close() error {
} }
func (c *Client) streamEvents() { func (c *Client) streamEvents() {
str, err := c.StreamEvents(context.Background(), &pb.StreamEventsParams{}) stream, err := c.StreamEvents(context.Background(), &pb.StreamEventsParams{})
if err != nil { if err != nil {
c.logger.Error("Failed to stream events", zap.Error(err)) c.logger.Error("Failed to stream events", zap.Error(err))
} }
ok := true ok := true
for ok { for ok {
evt, err := str.Recv() e, err := stream.Recv()
if err != nil { if err != nil {
c.logger.Error("Failed to receive event", zap.Error(err)) c.logger.Error("Failed to receive event", zap.Error(err))
break break
} }
evt.Log(c.logger, "Received event") if e.Type == pb.Event_PEER_CONNECTION_STATE_CHANGED {
c.Events <- evt if pcs, ok := e.Event.(*pb.Event_PeerConnectionStateChange); ok {
pk := *(*crypto.Key)(e.Peer)
cs := pcs.PeerConnectionStateChange.NewState.ConnectionState()
c.connectionStatesLock.Lock()
c.connectionStates[pk] = cs
c.connectionStatesCond.Broadcast()
c.connectionStatesLock.Unlock()
} }
} }
func (c *Client) WaitForEvent(flt *pb.Event) *pb.Event { e.Log(c.logger, "Received event")
for evt := range c.Events { c.Events <- e
if evt.Match(flt) {
return evt
} }
} }
func (c *Client) WaitForEvent(t pb.Event_Type, intf string, peer crypto.Key) *pb.Event {
for e := range c.Events {
if e.Type != t {
continue
}
if intf != "" && intf != e.Interface {
continue
}
if peer.IsSet() && !bytes.Equal(peer.Bytes(), e.Peer) {
continue
}
return e
}
return nil return nil
} }
func (c *Client) WaitPeerHandshake(peer crypto.Key) { func (c *Client) WaitForPeerHandshake(peer crypto.Key) {
c.WaitForEvent(&pb.Event{ for {
Type: "handshake", e := c.WaitForEvent(pb.Event_PEER_MODIFIED, "", peer)
State: "new",
}) ee, ok := e.Event.(*pb.Event_PeerModified)
if !ok {
continue
} }
func (c *Client) WaitPeerConnected() { mod := intf.PeerModifier(ee.PeerModified.Modified)
c.WaitForEvent(&pb.Event{ if mod.Is(intf.PeerModifiedHandshakeTime) {
Type: "state", return
State: "connected", }
}) }
}
func (c *Client) WaitForPeerConnectionState(peer crypto.Key, csd ice.ConnectionState) {
for {
c.connectionStatesLock.Lock()
for {
if cs, ok := c.connectionStates[peer]; ok && cs == csd {
c.connectionStatesLock.Unlock()
return
}
c.connectionStatesCond.Wait()
}
}
} }

View File

@@ -23,6 +23,24 @@ func (s *Server) GetStatus(ctx context.Context, _ *pb.Void) (*pb.Status, error)
func (s *Server) StreamEvents(params *pb.StreamEventsParams, stream pb.Socket_StreamEventsServer) error { func (s *Server) StreamEvents(params *pb.StreamEventsParams, stream pb.Socket_StreamEventsServer) error {
events := s.daemon.ListenEvents() events := s.daemon.ListenEvents()
// Send initial connection state of all peers
for _, i := range s.daemon.Interfaces {
for key, p := range i.Peers() {
e := &pb.Event{
Type: pb.Event_PEER_CONNECTION_STATE_CHANGED,
Interface: p.Interface.Name(),
Peer: key.Bytes(),
Event: &pb.Event_PeerConnectionStateChange{
PeerConnectionStateChange: &pb.PeerConnectionStateChangeEvent{
NewState: pb.NewConnectionState(p.ConnectionState),
},
},
}
stream.Send(e)
}
}
for e := range events { for e := range events {
stream.Send(e) stream.Send(e)
} }