Skip to content
Snippets Groups Projects
Commit fe160663 authored by Malte Bauch's avatar Malte Bauch
Browse files

Linter pleasing

parent bd54f85c
Branches
No related tags found
3 merge requests!11Big boom integration,!10Add linting,!6Draft: Akms ckms api implementation
Pipeline #180759 passed
......@@ -11,6 +11,7 @@ run:
- ekms/model
- ekms/models
- artifacts/
- ekms/api/go
skip-dirs-default: true
#skip-files:
# - http.go
......
......@@ -15,7 +15,6 @@ type HostnameHandler struct {
name string
paths map[string]struct{}
osClient osclient.Osclient
weight int
}
func NewHostnameHandler() *HostnameHandler {
......
......@@ -46,8 +46,6 @@ type EKMS struct {
quantumModulesMutex sync.RWMutex
kmsPeersMutex sync.Mutex
// TODO(maba): find a better name for this
// TODO: add mutex
keysForPathId map[uuid.UUID]string
routingTable map[uuid.UUID]*Route
routingTableMutex sync.RWMutex
KmsPeers map[string]*kmsPeer
......@@ -230,25 +228,25 @@ func (kms *EKMS) FindPeerUuid(lookup uuid.UUID) (peer *kmsPeer) {
}
func (kms *EKMS) RoutingTableDeepCopy() map[uuid.UUID]*Route {
copy := make(map[uuid.UUID]*Route, len(kms.KmsPeers))
routingTableCopy := make(map[uuid.UUID]*Route, len(kms.KmsPeers))
kms.routingTableMutex.Lock()
for k, v := range kms.routingTable {
copy[k] = v
routingTableCopy[k] = v
}
kms.routingTableMutex.Unlock()
return copy
return routingTableCopy
}
func (kms *EKMS) PeersDeepCopy() map[string]*kmsPeer {
copy := make(map[string]*kmsPeer, len(kms.KmsPeers))
peersCopy := make(map[string]*kmsPeer, len(kms.KmsPeers))
kms.kmsPeersMutex.Lock()
for k, v := range kms.KmsPeers {
copy[k] = v
peersCopy[k] = v
}
kms.kmsPeersMutex.Unlock()
return copy
return peersCopy
}
......@@ -17,8 +17,6 @@ import (
"google.golang.org/grpc/status"
)
var etsiPort = flag.Int("port", 50900, "The server port")
// TODO: remove etsiServer.
type etsiServer struct {
pb.UnimplementedKmsETSIServer
......
......@@ -24,12 +24,13 @@ const (
KmsPeerUnknown // not known, not initialized
)
type kmsPeerInfo interface {
GetKmsPeerStatus() KmsPeerStatus
GetKmsPeerId() uuid.UUID
GetKmsPeerQkdiId() uint32
KmsPeerKeyInit()
}
// NOTE: currently not used, could be of usage later on
// type kmsPeerInfo interface {
// GetKmsPeerStatus() KmsPeerStatus
// GetKmsPeerId() uuid.UUID
// GetKmsPeerQkdiId() uint32
// KmsPeerKeyInit()
// }
type kmsPeer struct {
peerClient pbIC.KmsTalkerClient
......@@ -40,10 +41,11 @@ type kmsPeer struct {
tcpSocket *net.TCPAddr // the IP address and TCP port (aka socket) of the kms peer
tcpSocketStr string // string rep. of tcpSocket
et CryptoAlgorithm
name string // the name of the kms peer
id uuid.UUID // uuid of the peer
quit chan bool // cancel the peer goroutine
eventBus *event.EventBus
// NOTE: currently not used, could be of usage later on
// name string // the name of the kms peer
id uuid.UUID // uuid of the peer
quit chan bool // cancel the peer goroutine
eventBus *event.EventBus
}
func NewKmsPeer(peerKmsId string, servQM QuantumModule, tcpSocketStr string, interComAddr string, eventBus *event.EventBus) (*kmsPeer, error) {
......
......@@ -291,7 +291,6 @@ func (eqe *ETSI014HTTPQuantumModule) Initialize() error {
if err := addETSIKeysToKeystore(eqe.keyStore, container.GetKeys()); err != nil {
log.Error(err)
break
}
}
}
......
......@@ -8,6 +8,7 @@ import (
etsi14 "code.fbi.h-da.de/danet/quant/ekms/api/go/rest/etsi/client"
"github.com/google/uuid"
"github.com/hashicorp/go-multierror"
)
func RandomItemFromMap[T comparable, M any](m map[T]M) (M, error) {
......@@ -59,7 +60,7 @@ func addETSIKeysToKeystore(keyStore *kmsKeyStore, keyContainer []etsi14.KeyConta
}
// NOTE: For demo purpose only.
func SendKmsInfoMessage(url string, json []byte) error {
func SendKmsInfoMessage(url string, json []byte) (err error) {
request, err := http.NewRequest("POST", url, bytes.NewBuffer(json))
if err != nil {
return err
......@@ -68,10 +69,16 @@ func SendKmsInfoMessage(url string, json []byte) error {
client := &http.Client{}
response, err := client.Do(request)
if err != nil {
response.Body.Close()
if closeError := response.Body.Close(); closeError != nil {
err = multierror.Append(err, closeError)
}
return err
}
defer response.Body.Close()
defer func() {
if closeError := response.Body.Close(); closeError != nil {
err = multierror.Append(err, closeError)
}
}()
return nil
}
......
......@@ -8,6 +8,7 @@ require (
github.com/google/uuid v1.3.1
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0
github.com/hashicorp/go-multierror v1.1.1
github.com/openconfig/gnmi v0.10.0
github.com/openconfig/goyang v1.4.2
github.com/openconfig/ygot v0.29.12
......@@ -32,6 +33,7 @@ require (
github.com/golang/glog v1.1.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
......
......@@ -56,7 +56,7 @@ func NewQuantumlayerEmuPRNG(client pb.KmsQkdmCommunicationServiceClient, logOutp
* Setup logging
*/
//What level
// What level
log.SetLevel(logLevel)
// Where to send log out put
log.SetOutput(logOutput)
......@@ -110,7 +110,7 @@ func (qlemuprng *QuantumlayerEmuPRNG) PowerOn() {
log.Errorf("QuantumlayerEmuPRNG: Sorry, the quantum layer is not configured for action. You've missed Configure()")
return
}
//qlemuprng.poweron = false
// qlemuprng.poweron = false
log.Infof("QuantumlayerEmuPRNG: is powering on...charging.")
if qlemuprng.generateKeys {
......@@ -137,7 +137,12 @@ func (qlemuprng *QuantumlayerEmuPRNG) PowerOn() {
defer qlemuprng.udpSrvConn.Close()
// Retrieve local UDP address and store it for further actions.
qlemuprng.qlLocalPort = qlemuprng.udpSrvConn.LocalAddr().(*net.UDPAddr)
tempPort, ok := qlemuprng.udpSrvConn.LocalAddr().(*net.UDPAddr)
if !ok {
return
}
qlemuprng.qlLocalPort = tempPort
// TODO: This does not seem to be necessary if the gle is not generating rands
// serve UDP incoming
......@@ -155,7 +160,7 @@ func (qlemuprng *QuantumlayerEmuPRNG) PowerOn() {
// Warning this is not checking the validity of the sender, i.e., spoofing is possible
if addr.String() == qlemuprng.qlPeer {
log.Debugf("QuantumlayerEmuPRNG: Peer %s listed", addr)
//dumb the received data into the channel and carry on
// dumb the received data into the channel and carry on
// TODO/XXX: no vetting for anything
// Unmarshall out of JSON
var inQBuffer QuantumPayloadElement
......@@ -193,7 +198,7 @@ func (qlemuprng *QuantumlayerEmuPRNG) AddPeer(addr *net.UDPAddr) {
if !qlemuprng.poweron {
return
}
//TODO/XXX check the incoming addr
// TODO/XXX check the incoming addr
// Add peer to the ....
qlemuprng.qlPeerMutex.Lock()
......@@ -216,7 +221,7 @@ func (qlemuprng *QuantumlayerEmuPRNG) AddPeer(addr *net.UDPAddr) {
// retrieve a new back of random numbers
newNumberBatch := qlemuprng.GenerateRandomNumbers()
// TODO: Replace this by some generic encapsulation reader and not just JSON
//Get JSON for transmission ready
// Get JSON for transmission ready
qpe := QuantumPayloadElement{time.Now().UnixNano(), len(newNumberBatch), &newNumberBatch}
// XXX/TODO: error must be handled
......@@ -353,7 +358,7 @@ func (store *NumberStore) receiveNumbers(incoming chan QuantumPayloadElement, cl
BulkKeyLength: receivedNumbers.BulkKeyLength,
BulkKey: receivedNumbers.BulkKey,
}
//store.bulkKeyStorage[receivedNumbers.BulkKeyId] = mem
// store.bulkKeyStorage[receivedNumbers.BulkKeyId] = mem
store.bulkKeyStorage = append(store.bulkKeyStorage, mem)
store.mu.Unlock()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment