Code change to make Solicit router.proto message
This commit is contained in:
@@ -29,8 +29,6 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrMsgUnknown is returned when unknown message is attempted to send or receive
|
||||
ErrMsgUnknown = errors.New("unknown message")
|
||||
// ErrClientNotFound is returned when client for tunnel channel could not be found
|
||||
ErrClientNotFound = errors.New("client not found")
|
||||
)
|
||||
@@ -277,8 +275,13 @@ func (n *network) processNetChan(client transport.Client, listener tunnel.Listen
|
||||
lastSeen: now,
|
||||
}
|
||||
n.Unlock()
|
||||
// get all the node peers down to MaxDepth encoded in protobuf message
|
||||
msg, err := n.node.getProtoTopology(MaxDepth)
|
||||
if err != nil {
|
||||
log.Debugf("Network unable to retrieve node peers: %s", err)
|
||||
}
|
||||
// advertise yourself to the network
|
||||
if err := n.sendMsg("peer", NetworkChannel); err != nil {
|
||||
if err := n.sendMsg("peer", msg, NetworkChannel); err != nil {
|
||||
log.Debugf("Network failed to advertise peers: %v", err)
|
||||
}
|
||||
// advertise all the routes when a new node has connected
|
||||
@@ -310,8 +313,10 @@ func (n *network) processNetChan(client transport.Client, listener tunnel.Listen
|
||||
}
|
||||
n.Unlock()
|
||||
// send a solicit message when discovering new peer
|
||||
// NOTE: we need to release the Lock here as sendMsg locsk, too
|
||||
if err := n.sendMsg("solicit", ControlChannel); err != nil {
|
||||
msg := &pbRtr.Solicit{
|
||||
Id: n.options.Id,
|
||||
}
|
||||
if err := n.sendMsg("solicit", msg, ControlChannel); err != nil {
|
||||
log.Debugf("Network failed to send solicit message: %s", err)
|
||||
}
|
||||
// after adding new peer go to the next step
|
||||
@@ -351,49 +356,15 @@ func (n *network) processNetChan(client transport.Client, listener tunnel.Listen
|
||||
}
|
||||
|
||||
// sendMsg sends a message to the tunnel channel
|
||||
func (n *network) sendMsg(msgType string, channel string) error {
|
||||
node := &pbNet.Node{
|
||||
Id: n.options.Id,
|
||||
Address: n.options.Address,
|
||||
}
|
||||
|
||||
var protoMsg proto.Message
|
||||
|
||||
switch msgType {
|
||||
case "connect":
|
||||
protoMsg = &pbNet.Connect{
|
||||
Node: node,
|
||||
}
|
||||
case "close":
|
||||
protoMsg = &pbNet.Close{
|
||||
Node: node,
|
||||
}
|
||||
case "solicit":
|
||||
protoMsg = &pbNet.Solicit{
|
||||
Node: node,
|
||||
}
|
||||
case "peer":
|
||||
n.RLock()
|
||||
var err error
|
||||
// get all the node peers down to MaxDepth
|
||||
protoMsg, err = n.node.getProtoTopology(MaxDepth)
|
||||
if err != nil {
|
||||
log.Debugf("Network unable to retrieve node peers: %s", err)
|
||||
return err
|
||||
}
|
||||
n.RUnlock()
|
||||
default:
|
||||
return ErrMsgUnknown
|
||||
}
|
||||
|
||||
body, err := proto.Marshal(protoMsg)
|
||||
func (n *network) sendMsg(method string, msg proto.Message, channel string) error {
|
||||
body, err := proto.Marshal(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// create transport message and chuck it down the pipe
|
||||
m := transport.Message{
|
||||
Header: map[string]string{
|
||||
"Micro-Method": msgType,
|
||||
"Micro-Method": method,
|
||||
},
|
||||
Body: body,
|
||||
}
|
||||
@@ -407,7 +378,7 @@ func (n *network) sendMsg(msgType string, channel string) error {
|
||||
}
|
||||
n.RUnlock()
|
||||
|
||||
log.Debugf("Network sending %s message from: %s", msgType, node.Id)
|
||||
log.Debugf("Network sending %s message from: %s", method, n.options.Id)
|
||||
if err := client.Send(&m); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -425,8 +396,16 @@ func (n *network) announce(client transport.Client) {
|
||||
case <-n.closed:
|
||||
return
|
||||
case <-announce.C:
|
||||
n.RLock()
|
||||
msg, err := n.node.getProtoTopology(MaxDepth)
|
||||
if err != nil {
|
||||
log.Debugf("Network unable to retrieve node peers: %s", err)
|
||||
n.RUnlock()
|
||||
continue
|
||||
}
|
||||
n.RUnlock()
|
||||
// advertise yourself to the network
|
||||
if err := n.sendMsg("peer", NetworkChannel); err != nil {
|
||||
if err := n.sendMsg("peer", msg, NetworkChannel); err != nil {
|
||||
log.Debugf("Network failed to advertise peers: %v", err)
|
||||
continue
|
||||
}
|
||||
@@ -598,12 +577,15 @@ func (n *network) processCtrlChan(client transport.Client, listener tunnel.Liste
|
||||
lastSeen: now,
|
||||
}
|
||||
n.peers[pbRtrAdvert.Id] = advertNode
|
||||
n.Unlock()
|
||||
// send a solicit message when discovering a new node
|
||||
if err := n.sendMsg("solicit", ControlChannel); err != nil {
|
||||
msg := &pbRtr.Solicit{
|
||||
Id: n.options.Id,
|
||||
}
|
||||
if err := n.sendMsg("solicit", msg, ControlChannel); err != nil {
|
||||
log.Debugf("Network failed to send solicit message: %s", err)
|
||||
}
|
||||
}
|
||||
n.Unlock()
|
||||
|
||||
var events []*router.Event
|
||||
for _, event := range pbRtrAdvert.Events {
|
||||
@@ -660,14 +642,14 @@ func (n *network) processCtrlChan(client transport.Client, listener tunnel.Liste
|
||||
continue
|
||||
}
|
||||
case "solicit":
|
||||
pbNetSolicit := &pbNet.Solicit{}
|
||||
if err := proto.Unmarshal(m.Body, pbNetSolicit); err != nil {
|
||||
pbRtrSolicit := &pbRtr.Solicit{}
|
||||
if err := proto.Unmarshal(m.Body, pbRtrSolicit); err != nil {
|
||||
log.Debugf("Network fail to unmarshal solicit message: %v", err)
|
||||
continue
|
||||
}
|
||||
log.Debugf("Network received solicit message from: %s", pbNetSolicit.Node.Id)
|
||||
// don't process your own messages
|
||||
if pbNetSolicit.Node.Id == n.options.Id {
|
||||
log.Debugf("Network received solicit message from: %s", pbRtrSolicit.Id)
|
||||
// ignore solicitation when requested by you
|
||||
if pbRtrSolicit.Id == n.options.Id {
|
||||
continue
|
||||
}
|
||||
// advertise all the routes when a new node has connected
|
||||
@@ -707,29 +689,14 @@ func (n *network) advertise(client transport.Client, advertChan <-chan *router.A
|
||||
}
|
||||
events = append(events, e)
|
||||
}
|
||||
pbRtrAdvert := &pbRtr.Advert{
|
||||
msg := &pbRtr.Advert{
|
||||
Id: advert.Id,
|
||||
Type: pbRtr.AdvertType(advert.Type),
|
||||
Timestamp: advert.Timestamp.UnixNano(),
|
||||
Events: events,
|
||||
}
|
||||
body, err := proto.Marshal(pbRtrAdvert)
|
||||
if err != nil {
|
||||
// TODO: should we bail here?
|
||||
log.Debugf("Network failed to marshal advert message: %v", err)
|
||||
continue
|
||||
}
|
||||
// create transport message and chuck it down the pipe
|
||||
m := transport.Message{
|
||||
Header: map[string]string{
|
||||
"Micro-Method": "advert",
|
||||
},
|
||||
Body: body,
|
||||
}
|
||||
|
||||
log.Debugf("Network sending advert message from: %s", pbRtrAdvert.Id)
|
||||
if err := client.Send(&m); err != nil {
|
||||
log.Debugf("Network failed to send advert %s: %v", pbRtrAdvert.Id, err)
|
||||
if err := n.sendMsg("advert", msg, NetworkChannel); err != nil {
|
||||
log.Debugf("Network failed to advertise routes: %v", err)
|
||||
continue
|
||||
}
|
||||
case <-n.closed:
|
||||
@@ -814,7 +781,13 @@ func (n *network) Connect() error {
|
||||
// NOTE: in theory we could do this as soon as
|
||||
// Dial to NetworkChannel succeeds, but instead
|
||||
// we initialize all other node resources first
|
||||
if err := n.sendMsg("connect", NetworkChannel); err != nil {
|
||||
msg := &pbNet.Connect{
|
||||
Node: &pbNet.Node{
|
||||
Id: n.options.Id,
|
||||
Address: n.options.Address,
|
||||
},
|
||||
}
|
||||
if err := n.sendMsg("connect", msg, NetworkChannel); err != nil {
|
||||
log.Debugf("Network failed to send connect message: %s", err)
|
||||
}
|
||||
|
||||
@@ -880,9 +853,13 @@ func (n *network) Close() error {
|
||||
case <-n.closed:
|
||||
return nil
|
||||
default:
|
||||
// send close message only if we managed to connect to NetworkChannel
|
||||
log.Debugf("Sending close message from: %s", n.options.Id)
|
||||
if err := n.sendMsg("close", NetworkChannel); err != nil {
|
||||
msg := &pbNet.Close{
|
||||
Node: &pbNet.Node{
|
||||
Id: n.options.Id,
|
||||
Address: n.options.Address,
|
||||
},
|
||||
}
|
||||
if err := n.sendMsg("close", msg, NetworkChannel); err != nil {
|
||||
log.Debugf("Network failed to send close message: %s", err)
|
||||
}
|
||||
// TODO: send close message to the network channel
|
||||
|
||||
@@ -388,47 +388,6 @@ func (m *Close) GetNode() *Node {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Solicit is sent when soliciting routes from the network nodes
|
||||
type Solicit struct {
|
||||
// network node
|
||||
Node *Node `protobuf:"bytes,1,opt,name=node,proto3" json:"node,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Solicit) Reset() { *m = Solicit{} }
|
||||
func (m *Solicit) String() string { return proto.CompactTextString(m) }
|
||||
func (*Solicit) ProtoMessage() {}
|
||||
func (*Solicit) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_8571034d60397816, []int{9}
|
||||
}
|
||||
|
||||
func (m *Solicit) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Solicit.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Solicit) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Solicit.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *Solicit) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Solicit.Merge(m, src)
|
||||
}
|
||||
func (m *Solicit) XXX_Size() int {
|
||||
return xxx_messageInfo_Solicit.Size(m)
|
||||
}
|
||||
func (m *Solicit) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Solicit.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Solicit proto.InternalMessageInfo
|
||||
|
||||
func (m *Solicit) GetNode() *Node {
|
||||
if m != nil {
|
||||
return m.Node
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Peer is used to advertise node peers
|
||||
type Peer struct {
|
||||
// network node
|
||||
@@ -444,7 +403,7 @@ func (m *Peer) Reset() { *m = Peer{} }
|
||||
func (m *Peer) String() string { return proto.CompactTextString(m) }
|
||||
func (*Peer) ProtoMessage() {}
|
||||
func (*Peer) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_8571034d60397816, []int{10}
|
||||
return fileDescriptor_8571034d60397816, []int{9}
|
||||
}
|
||||
|
||||
func (m *Peer) XXX_Unmarshal(b []byte) error {
|
||||
@@ -489,36 +448,35 @@ func init() {
|
||||
proto.RegisterType((*Node)(nil), "go.micro.network.Node")
|
||||
proto.RegisterType((*Connect)(nil), "go.micro.network.Connect")
|
||||
proto.RegisterType((*Close)(nil), "go.micro.network.Close")
|
||||
proto.RegisterType((*Solicit)(nil), "go.micro.network.Solicit")
|
||||
proto.RegisterType((*Peer)(nil), "go.micro.network.Peer")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("network.proto", fileDescriptor_8571034d60397816) }
|
||||
|
||||
var fileDescriptor_8571034d60397816 = []byte{
|
||||
// 382 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0x51, 0x4f, 0xea, 0x30,
|
||||
0x14, 0xc7, 0x61, 0x17, 0xee, 0xe0, 0x70, 0xb9, 0x92, 0x3e, 0x98, 0x85, 0x04, 0x03, 0x7d, 0x22,
|
||||
0x46, 0x87, 0x81, 0xf0, 0xe6, 0x1b, 0x89, 0xbe, 0x10, 0x62, 0xc0, 0x0f, 0xa0, 0x6c, 0xcd, 0x6c,
|
||||
0x84, 0x9d, 0xd9, 0x96, 0x18, 0x3f, 0x9f, 0x5f, 0xcc, 0xb4, 0xdd, 0x18, 0x02, 0xd3, 0xf0, 0xb6,
|
||||
0x9e, 0xf3, 0x3f, 0xbf, 0xff, 0xda, 0xfe, 0x0b, 0xcd, 0x98, 0xa9, 0x77, 0x14, 0xaf, 0x7e, 0x22,
|
||||
0x50, 0x21, 0x69, 0x45, 0xe8, 0xaf, 0x79, 0x20, 0xd0, 0x4f, 0xeb, 0xed, 0x51, 0xc4, 0xd5, 0xcb,
|
||||
0x66, 0xe9, 0x07, 0xb8, 0x1e, 0x98, 0xce, 0x20, 0xc2, 0x6b, 0xfb, 0x21, 0x70, 0xa3, 0x98, 0x18,
|
||||
0x98, 0xc9, 0x74, 0x61, 0x31, 0xb4, 0x09, 0x8d, 0x29, 0x97, 0x6a, 0xce, 0xde, 0x36, 0x4c, 0x2a,
|
||||
0x7a, 0x0b, 0xff, 0xec, 0x52, 0x26, 0x18, 0x4b, 0x46, 0xae, 0xa0, 0x1a, 0x63, 0xc8, 0xa4, 0x57,
|
||||
0xee, 0xfe, 0xe9, 0x37, 0x86, 0xe7, 0xfe, 0xbe, 0xab, 0x3f, 0xc3, 0x90, 0xcd, 0xad, 0x88, 0x76,
|
||||
0xa0, 0xf1, 0xc0, 0x98, 0x48, 0x61, 0xe4, 0x3f, 0x38, 0x3c, 0xf4, 0xca, 0xdd, 0x72, 0xbf, 0x3e,
|
||||
0x77, 0x78, 0xa8, 0xe1, 0xb6, 0x9d, 0xc3, 0x13, 0xc6, 0xc4, 0xaf, 0x70, 0x23, 0xa2, 0x3d, 0x38,
|
||||
0x7b, 0xc4, 0x04, 0x57, 0x18, 0x7d, 0x14, 0x19, 0xdc, 0x41, 0x2b, 0x97, 0xa4, 0x26, 0x43, 0xa8,
|
||||
0xa9, 0xb4, 0x66, 0x94, 0x47, 0x7d, 0xcc, 0x6f, 0x6d, 0x75, 0xf4, 0x06, 0x2a, 0xda, 0x79, 0x9f,
|
||||
0x4f, 0x3c, 0x70, 0x9f, 0xc3, 0x50, 0x30, 0x29, 0x3d, 0xc7, 0x14, 0xb3, 0x25, 0x1d, 0x83, 0x3b,
|
||||
0xc1, 0x38, 0x66, 0x81, 0x22, 0x97, 0x50, 0xd1, 0xa7, 0x51, 0x6c, 0x66, 0x36, 0x65, 0x34, 0x74,
|
||||
0x04, 0xd5, 0xc9, 0x0a, 0x25, 0x3b, 0x69, 0x68, 0x0c, 0xee, 0x02, 0x57, 0x3c, 0xe0, 0xa7, 0x79,
|
||||
0x3d, 0x41, 0x45, 0x6f, 0xf3, 0x94, 0x99, 0xfc, 0x86, 0x9c, 0xa2, 0x1b, 0x32, 0x27, 0x67, 0x45,
|
||||
0xc3, 0x4f, 0x07, 0xdc, 0x99, 0xad, 0x93, 0x29, 0xd4, 0x75, 0x90, 0x34, 0x4b, 0x92, 0xce, 0xe1,
|
||||
0xdc, 0x4e, 0xe8, 0xda, 0x17, 0x45, 0x6d, 0x7b, 0x85, 0xb4, 0x94, 0xd1, 0xb4, 0xd9, 0x51, 0xda,
|
||||
0x4e, 0xea, 0x8e, 0xd1, 0x76, 0x53, 0x47, 0x4b, 0x64, 0x01, 0xb5, 0x2c, 0x26, 0xa4, 0x77, 0xa8,
|
||||
0xde, 0x4b, 0x59, 0x9b, 0xfe, 0x24, 0xd9, 0x42, 0xef, 0x01, 0xcc, 0x4f, 0xeb, 0xc7, 0x25, 0x89,
|
||||
0x97, 0xcf, 0xa4, 0xcf, 0x2d, 0xa3, 0x75, 0x0e, 0x3a, 0xdf, 0xf7, 0xba, 0xfc, 0x6b, 0x1e, 0xe6,
|
||||
0xe8, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x0d, 0xd5, 0xbf, 0xdc, 0xf0, 0x03, 0x00, 0x00,
|
||||
// 371 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xc1, 0x4e, 0xc2, 0x40,
|
||||
0x10, 0x86, 0xa1, 0x82, 0xc0, 0x20, 0x4a, 0xf6, 0x60, 0x1a, 0x12, 0x0c, 0xec, 0x89, 0x18, 0x2d,
|
||||
0x06, 0xe2, 0xcd, 0x1b, 0x89, 0x5e, 0x08, 0x31, 0xe8, 0x03, 0x28, 0x74, 0x52, 0x1b, 0xa1, 0x53,
|
||||
0x77, 0x97, 0x18, 0x9f, 0xcf, 0x17, 0x33, 0xbb, 0xdb, 0x52, 0x04, 0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f2, 0x5b, 0xa8, 0x8c, 0x28, 0x8a, 0x70,
|
||||
0xae, 0xd8, 0x25, 0x94, 0x74, 0x37, 0xf2, 0xcd, 0xcc, 0x4f, 0x19, 0x0d, 0x1f, 0x42, 0x79, 0xb4,
|
||||
0x20, 0x89, 0x07, 0x15, 0xbd, 0x40, 0x49, 0xdf, 0xf7, 0x90, 0x9a, 0xac, 0xd5, 0x4e, 0x5e, 0xab,
|
||||
0x4d, 0x0b, 0xac, 0x68, 0xf0, 0xed, 0x40, 0x65, 0x62, 0xe3, 0x6c, 0x0c, 0x35, 0x3d, 0x11, 0x9a,
|
||||
0x25, 0x59, 0x7b, 0xb7, 0x6e, 0x63, 0x7a, 0x5a, 0x17, 0x79, 0x69, 0xfb, 0x16, 0xbc, 0x90, 0xd2,
|
||||
0xb4, 0xd9, 0x5e, 0xda, 0xc6, 0xf8, 0xec, 0xa3, 0x6d, 0x8e, 0x0f, 0x2f, 0xb0, 0x27, 0xa8, 0xa6,
|
||||
0xef, 0xcd, 0xba, 0xbb, 0xea, 0xad, 0x71, 0x69, 0xf1, 0xbf, 0x24, 0x6b, 0xe8, 0x03, 0x80, 0xb9,
|
||||
0xb4, 0xde, 0x12, 0xc9, 0xdc, 0xac, 0x26, 0xd9, 0x9b, 0x94, 0xd6, 0xde, 0xc9, 0xfc, 0xfe, 0xd7,
|
||||
0xd9, 0xb1, 0xd9, 0xb0, 0xe1, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x41, 0x11, 0x04, 0x65, 0xb9,
|
||||
0x03, 0x00, 0x00,
|
||||
}
|
||||
|
||||
@@ -63,12 +63,6 @@ message Close {
|
||||
Node node = 1;
|
||||
}
|
||||
|
||||
// Solicit is sent when soliciting routes from the network nodes
|
||||
message Solicit {
|
||||
// network node
|
||||
Node node = 1;
|
||||
}
|
||||
|
||||
// Peer is used to advertise node peers
|
||||
message Peer {
|
||||
// network node
|
||||
|
||||
Reference in New Issue
Block a user