summaryrefslogtreecommitdiffhomepage
path: root/server/peer.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-18 17:23:22 -0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-19 10:28:45 +0900
commitb1c8ed363bdab0d3618077e93a79df227559539c (patch)
tree6b56b6cc5083c3556e80806c0153fd83b9b5c24e /server/peer.go
parentf7568d45ca887d967d493d9ae221a118a06aab44 (diff)
server: add message delivery between peers
a peer notifies other peers of its event (join,leave,bgp state change, updates, etc) It would have better performance for a peer to send a message to a channel of another peer directly. However, for the code simplicity, the hub-and-spoke model is used for now. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/peer.go')
-rw-r--r--server/peer.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/server/peer.go b/server/peer.go
index cf712b57..52a8205f 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -31,16 +31,20 @@ type Peer struct {
acceptedConnCh chan *net.TCPConn
incoming chan *bgp.BGPMessage
outgoing chan *bgp.BGPMessage
+ inEventCh chan *message
+ outEventCh chan *message
fsm *FSM
}
-func NewPeer(g config.GlobalType, peer config.NeighborType) *Peer {
+func NewPeer(g config.GlobalType, peer config.NeighborType, outEventCh chan *message) *Peer {
p := &Peer{
globalConfig: g,
peerConfig: peer,
acceptedConnCh: make(chan *net.TCPConn),
incoming: make(chan *bgp.BGPMessage, 4096),
outgoing: make(chan *bgp.BGPMessage, 4096),
+ inEventCh: make(chan *message, 4096),
+ outEventCh: outEventCh,
}
p.fsm = NewFSM(&g, &peer, p.acceptedConnCh, p.incoming, p.outgoing)
p.t.Go(p.loop)
@@ -70,6 +74,8 @@ func (peer *Peer) loop() error {
j, _ := json.Marshal(m)
fmt.Println(string(j))
}
+ case m := <-peer.inEventCh:
+ fmt.Println(m)
}
}
}
@@ -83,3 +89,16 @@ func (peer *Peer) Stop() error {
func (peer *Peer) PassConn(conn *net.TCPConn) {
peer.acceptedConnCh <- conn
}
+
+func (peer *Peer) SendMessage(msg *message) {
+ peer.inEventCh <- msg
+}
+
+func (peer *Peer) sendToHub(destination string, event int, data interface{}) {
+ peer.outEventCh <- &message{
+ src: peer.peerConfig.NeighborAddress.String(),
+ dst: destination,
+ event: event,
+ data: data,
+ }
+}