Skip to content
Snippets Groups Projects
Commit 993bd7bd authored by Martin Stiemerling's avatar Martin Stiemerling :speech_balloon:
Browse files

ExternalNotifier for KMSPeer

parent c908f102
No related branches found
No related tags found
1 merge request!9First working draft version
...@@ -18,9 +18,9 @@ import ( ...@@ -18,9 +18,9 @@ import (
) )
type Qkdnkms interface { type Qkdnkms interface {
AddExternalNotifierGeneral(chan bool) // used to indicate unspecific changes //AddExternalNotifierGeneral(chan bool) // used to indicate unspecific changes
AddExternalNotifierQLE(chan bool) // used to indicate changes to specific Quantum Link Element (QLE) AddExternalNotifierQLE(chan uint32) // used to indicate changes to specific Quantum Link Element (QLE)
AddExternalNotifierKMSPeer(chan bool) // used to indicate changes to specific KMSPeer AddExternalNotifierKMSPeer(chan string) // used to indicate changes to specific KMSPeer
AddQuantumElement() *QuantumElement AddQuantumElement() *QuantumElement
GlobalKeyHandler(time.Duration) error GlobalKeyHandler(time.Duration) error
AddPeer(kmsPeerSocket string, servingQLE *QuantumElement) AddPeer(kmsPeerSocket string, servingQLE *QuantumElement)
...@@ -31,12 +31,14 @@ type qlElementLinkID int ...@@ -31,12 +31,14 @@ type qlElementLinkID int
// The general emulated KMS // The general emulated KMS
type EKMS struct { type EKMS struct {
kmsName string kmsName string
kmsUUID uuid.UUID kmsUUID uuid.UUID
qleMapMutex sync.Mutex qleMapMutex sync.Mutex
QuantumElements map[uint32]*QuantumElement QuantumElements map[uint32]*QuantumElement
kmsPeersMutex sync.Mutex externalNotifierQLE chan uint32
KmsPeers map[string]*kmsPeer kmsPeersMutex sync.Mutex
KmsPeers map[string]*kmsPeer
externalNotifierKMSPeer chan string
pbETSI.UnimplementedKmsETSIServer pbETSI.UnimplementedKmsETSIServer
pbIC.UnimplementedKmsTalkerServer pbIC.UnimplementedKmsTalkerServer
} }
...@@ -60,10 +62,12 @@ type QuantumElement struct { ...@@ -60,10 +62,12 @@ type QuantumElement struct {
func NewEKMS(kmsName string, kmsUUID uuid.UUID) (newEKMS *EKMS) { func NewEKMS(kmsName string, kmsUUID uuid.UUID) (newEKMS *EKMS) {
return &EKMS{ return &EKMS{
kmsName: kmsName, kmsName: kmsName,
kmsUUID: kmsUUID, kmsUUID: kmsUUID,
QuantumElements: make(map[uint32]*QuantumElement), QuantumElements: make(map[uint32]*QuantumElement),
KmsPeers: make(map[string]*kmsPeer), 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) { ...@@ -163,7 +167,7 @@ func (kms *EKMS) AddPeer(kmsPeerSocket string, servingQLE *QuantumElement) {
if _, there := kms.KmsPeers[kmsPeerSocket]; there { if _, there := kms.KmsPeers[kmsPeerSocket]; there {
log.Fatalf("Trying to add existing peer %s", kmsPeerSocket) log.Fatalf("Trying to add existing peer %s", kmsPeerSocket)
} }
peer := NewKmsPeer(servingQLE) peer := NewKmsPeer(servingQLE, kms.externalNotifierKMSPeer)
peer.tcpSocketStr = kmsPeerSocket peer.tcpSocketStr = kmsPeerSocket
kms.kmsPeersMutex.Lock() kms.kmsPeersMutex.Lock()
...@@ -177,3 +181,11 @@ func (kms *EKMS) AddPeer(kmsPeerSocket string, servingQLE *QuantumElement) { ...@@ -177,3 +181,11 @@ func (kms *EKMS) AddPeer(kmsPeerSocket string, servingQLE *QuantumElement) {
func (kms *EKMS) RemovePeer(kmsPeerSocket string) { 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
}
...@@ -28,19 +28,21 @@ type kmsPeerInfo interface { ...@@ -28,19 +28,21 @@ type kmsPeerInfo interface {
} }
type kmsPeer struct { type kmsPeer struct {
peerStatus KmsPeerStatus externalNotifierKMSPeer chan string
servingQLE *QuantumElement peerStatus KmsPeerStatus
tcpSocket net.TCPAddr // the IP address and TCP port (aka socket) of the kms peer servingQLE *QuantumElement
tcpSocketStr string // string rep. of tcpSocket tcpSocket net.TCPAddr // the IP address and TCP port (aka socket) of the kms peer
name string // the name of the kms peer tcpSocketStr string // string rep. of tcpSocket
id uuid.UUID // uuid of the peer 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{ return kmsPeer{
peerStatus: kmsPeerUnknown, peerStatus: kmsPeerUnknown,
servingQLE: servQLE, servingQLE: servQLE,
id: uuid.New(), id: uuid.New(),
externalNotifierKMSPeer: in,
} }
} }
...@@ -72,6 +74,11 @@ func (ph *kmsPeer) PeerHandler(kmsName string) { ...@@ -72,6 +74,11 @@ func (ph *kmsPeer) PeerHandler(kmsName string) {
// Works and peer moves to kmsPeerUp // Works and peer moves to kmsPeerUp
ph.peerStatus = 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) 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. // By now, do check only the liveliness of the peer, nothing else.
...@@ -84,6 +91,10 @@ func (ph *kmsPeer) PeerHandler(kmsName string) { ...@@ -84,6 +91,10 @@ func (ph *kmsPeer) PeerHandler(kmsName string) {
if err != nil { if err != nil {
log.Printf("could not greet: %v", err) log.Printf("could not greet: %v", err)
ph.peerStatus = kmsPeerDown ph.peerStatus = kmsPeerDown
// Send notification about change
if ph.externalNotifierKMSPeer != nil {
ph.externalNotifierKMSPeer <- ph.tcpSocketStr
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment