diff --git a/kms/kms.go b/kms/kms.go index d5cb16cd8182ef30e36de23f467a04fc578dfb6d..f4bdf223391b3d003cad15f9cde05d7084b2dc67 100644 --- a/kms/kms.go +++ b/kms/kms.go @@ -18,9 +18,9 @@ import ( ) type Qkdnkms interface { - AddExternalNotifierGeneral(chan bool) // used to indicate unspecific changes - AddExternalNotifierQLE(chan bool) // used to indicate changes to specific Quantum Link Element (QLE) - AddExternalNotifierKMSPeer(chan bool) // used to indicate changes to specific KMSPeer + //AddExternalNotifierGeneral(chan bool) // used to indicate unspecific changes + AddExternalNotifierQLE(chan uint32) // used to indicate changes to specific Quantum Link Element (QLE) + AddExternalNotifierKMSPeer(chan string) // used to indicate changes to specific KMSPeer AddQuantumElement() *QuantumElement GlobalKeyHandler(time.Duration) error AddPeer(kmsPeerSocket string, servingQLE *QuantumElement) @@ -31,12 +31,14 @@ type qlElementLinkID int // The general emulated KMS type EKMS struct { - kmsName string - kmsUUID uuid.UUID - qleMapMutex sync.Mutex - QuantumElements map[uint32]*QuantumElement - kmsPeersMutex sync.Mutex - KmsPeers map[string]*kmsPeer + kmsName string + kmsUUID uuid.UUID + qleMapMutex sync.Mutex + QuantumElements map[uint32]*QuantumElement + externalNotifierQLE chan uint32 + kmsPeersMutex sync.Mutex + KmsPeers map[string]*kmsPeer + externalNotifierKMSPeer chan string pbETSI.UnimplementedKmsETSIServer pbIC.UnimplementedKmsTalkerServer } @@ -60,10 +62,12 @@ type QuantumElement struct { func NewEKMS(kmsName string, kmsUUID uuid.UUID) (newEKMS *EKMS) { return &EKMS{ - kmsName: kmsName, - kmsUUID: kmsUUID, - QuantumElements: make(map[uint32]*QuantumElement), - KmsPeers: make(map[string]*kmsPeer), + kmsName: kmsName, + kmsUUID: kmsUUID, + QuantumElements: make(map[uint32]*QuantumElement), + KmsPeers: make(map[string]*kmsPeer), + externalNotifierQLE: nil, // just be surely set to nil! + externalNotifierKMSPeer: nil, // just be surely set to nil! } } @@ -163,7 +167,7 @@ func (kms *EKMS) AddPeer(kmsPeerSocket string, servingQLE *QuantumElement) { if _, there := kms.KmsPeers[kmsPeerSocket]; there { log.Fatalf("Trying to add existing peer %s", kmsPeerSocket) } - peer := NewKmsPeer(servingQLE) + peer := NewKmsPeer(servingQLE, kms.externalNotifierKMSPeer) peer.tcpSocketStr = kmsPeerSocket kms.kmsPeersMutex.Lock() @@ -177,3 +181,11 @@ func (kms *EKMS) AddPeer(kmsPeerSocket string, servingQLE *QuantumElement) { func (kms *EKMS) RemovePeer(kmsPeerSocket string) { } + +func (kms *EKMS) AddExternalNotifierQLE(in chan uint32) { + kms.externalNotifierQLE = in +} + +func (kms *EKMS) AddExternalNotifierKMSPeer(in chan string) { + kms.externalNotifierKMSPeer = in +} diff --git a/kms/kmspeers.go b/kms/kmspeers.go index 1b27e7352c41efd554f42fb85bbad7cc29f4ce7b..dbe077501a311f9cdd87ee95ec8e83a9b7e641c2 100644 --- a/kms/kmspeers.go +++ b/kms/kmspeers.go @@ -28,19 +28,21 @@ type kmsPeerInfo interface { } type kmsPeer struct { - peerStatus KmsPeerStatus - servingQLE *QuantumElement - tcpSocket net.TCPAddr // the IP address and TCP port (aka socket) of the kms peer - tcpSocketStr string // string rep. of tcpSocket - name string // the name of the kms peer - id uuid.UUID // uuid of the peer + externalNotifierKMSPeer chan string + peerStatus KmsPeerStatus + servingQLE *QuantumElement + tcpSocket net.TCPAddr // the IP address and TCP port (aka socket) of the kms peer + tcpSocketStr string // string rep. of tcpSocket + name string // the name of the kms peer + id uuid.UUID // uuid of the peer } -func NewKmsPeer(servQLE *QuantumElement) (peer kmsPeer) { +func NewKmsPeer(servQLE *QuantumElement, in chan string) (peer kmsPeer) { return kmsPeer{ - peerStatus: kmsPeerUnknown, - servingQLE: servQLE, - id: uuid.New(), + peerStatus: kmsPeerUnknown, + servingQLE: servQLE, + id: uuid.New(), + externalNotifierKMSPeer: in, } } @@ -72,6 +74,11 @@ func (ph *kmsPeer) PeerHandler(kmsName string) { // Works and peer moves to kmsPeerUp ph.peerStatus = kmsPeerUp + // Send notification about change + if ph.externalNotifierKMSPeer != nil { + ph.externalNotifierKMSPeer <- ph.tcpSocketStr + } + log.Printf("Greeting: %s which is now in peerStatus %d", r.GetPeerKmsName(), ph.peerStatus) // By now, do check only the liveliness of the peer, nothing else. @@ -84,6 +91,10 @@ func (ph *kmsPeer) PeerHandler(kmsName string) { if err != nil { log.Printf("could not greet: %v", err) ph.peerStatus = kmsPeerDown + // Send notification about change + if ph.externalNotifierKMSPeer != nil { + ph.externalNotifierKMSPeer <- ph.tcpSocketStr + } } }