Skip to content

Commit

Permalink
fix: linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
romshark committed Feb 27, 2025
1 parent 6641450 commit 429b5e5
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 68 deletions.
27 changes: 14 additions & 13 deletions control/beaconing/propagator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ func TestPropagatorRunNonCore(t *testing.T) {
gomock.Any()).Times(1).DoAndReturn(

func(_ context.Context, _ addr.IA, egIfID uint16,
nextHop *net.UDPAddr) (beaconing.Sender, error) {

nextHop *net.UDPAddr,
) (beaconing.Sender, error) {
sender := mock_beaconing.NewMockSender(mctrl)
sender.EXPECT().Send(gomock.Any(), gomock.Any()).Times(3).DoAndReturn(
func(_ context.Context, b *seg.PathSegment) error {
validateSend(t, b, egIfID, nextHop, pub, topo)
func(ctx context.Context, b *seg.PathSegment) error {
validateSend(ctx, t, b, egIfID, nextHop, pub, topo)
return nil
},
)
Expand Down Expand Up @@ -167,12 +167,12 @@ func TestPropagatorRunCore(t *testing.T) {
senderFactory.EXPECT().NewSender(gomock.Any(), gomock.Any(), uint16(1121),
gomock.Any()).DoAndReturn(
func(_ context.Context, _ addr.IA, egIfID uint16,
nextHop *net.UDPAddr) (beaconing.Sender, error) {

nextHop *net.UDPAddr,
) (beaconing.Sender, error) {
sender := mock_beaconing.NewMockSender(mctrl)
sender.EXPECT().Send(gomock.Any(), gomock.Any()).Times(2).DoAndReturn(
func(_ context.Context, b *seg.PathSegment) error {
validateSend(t, b, egIfID, nextHop, pub, topo)
func(ctx context.Context, b *seg.PathSegment) error {
validateSend(ctx, t, b, egIfID, nextHop, pub, topo)
return nil
},
)
Expand All @@ -183,12 +183,12 @@ func TestPropagatorRunCore(t *testing.T) {
senderFactory.EXPECT().NewSender(gomock.Any(), gomock.Any(), uint16(1113),
gomock.Any()).DoAndReturn(
func(_ context.Context, _ addr.IA, egIfID uint16,
nextHop *net.UDPAddr) (beaconing.Sender, error) {

nextHop *net.UDPAddr,
) (beaconing.Sender, error) {
sender := mock_beaconing.NewMockSender(mctrl)
sender.EXPECT().Send(gomock.Any(), gomock.Any()).Times(1).DoAndReturn(
func(_ context.Context, b *seg.PathSegment) error {
validateSend(t, b, egIfID, nextHop, pub, topo)
func(ctx context.Context, b *seg.PathSegment) error {
validateSend(ctx, t, b, egIfID, nextHop, pub, topo)
return nil
},
)
Expand Down Expand Up @@ -275,6 +275,7 @@ func TestPropagatorFastRecovery(t *testing.T) {
}

func validateSend(
ctx context.Context,
t *testing.T,
b *seg.PathSegment,
egIfID uint16,
Expand All @@ -284,7 +285,7 @@ func validateSend(
) {
// Check the beacon is valid and verifiable.
assert.NoError(t, b.Validate(seg.ValidateBeacon))
assert.NoError(t, b.VerifyASEntry(context.Background(),
assert.NoError(t, b.VerifyASEntry(ctx,
segVerifier{pubKey: pub}, b.MaxIdx()))
// Extract the hop field from the current AS entry to compare.
hopF := b.ASEntries[b.MaxIdx()].HopEntry.HopField
Expand Down
9 changes: 4 additions & 5 deletions control/cmd/control/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func realMain(ctx context.Context) error {
MTU: topo.MTU(),
Topology: adaptTopology(topo),
}
quicStack, err := nc.QUICStack()
quicStack, err := nc.QUICStack(ctx)
if err != nil {
return serrors.Wrap("initializing QUIC stack", err)
}
Expand Down Expand Up @@ -393,10 +393,11 @@ func realMain(ctx context.Context) error {
},
Registrations: libmetrics.NewPromCounter(metrics.SegmentRegistrationsTotal),
})

}

signer := cs.NewSigner(topo.IA(), trustDB, globalCfg.General.ConfigDir)
ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()
signer := cs.NewSigner(ctx, topo.IA(), trustDB, globalCfg.General.ConfigDir)

var chainBuilder renewal.ChainBuilder
var caClient *caapi.Client
Expand Down Expand Up @@ -837,7 +838,6 @@ func createBeaconStore(
policyConfig config.Policies,
provider beacon.ChainProvider,
) (cs.Store, bool, error) {

if core {
policies, err := cs.LoadCorePolicies(policyConfig)
if err != nil {
Expand Down Expand Up @@ -967,7 +967,6 @@ func getCAHealth(
ctx context.Context,
caClient *caapi.Client,
) (api.CAHealthStatus, error) {

logger := log.FromCtx(ctx)
rep, err := caClient.GetHealthcheck(ctx)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion control/drkey/grpc/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ func TestLevel1KeyFetching(t *testing.T) {
ctrl := gomock.NewController(t)

lvl1db := mock_grpc.NewMockEngine(ctrl)
lvl1db.EXPECT().DeriveLevel1(gomock.Any(), gomock.Any()).AnyTimes().Return(drkey.Level1Key{}, nil)
lvl1db.EXPECT().DeriveLevel1(gomock.Any(), gomock.Any()).
AnyTimes().
Return(drkey.Level1Key{}, nil)

db := mock_trust.NewMockDB(ctrl)
db.EXPECT().SignedTRC(gomock.Any(), gomock.Any()).AnyTimes().Return(trc, nil)
Expand Down
4 changes: 3 additions & 1 deletion control/drkey/service_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ func (s *ServiceEngine) GetLevel1PrefetchInfo() []Level1PrefetchInfo {
}

// DeriveLevel1 returns a Level1 key based on the presented information.
func (s *ServiceEngine) DeriveLevel1(ctx context.Context, meta drkey.Level1Meta) (drkey.Level1Key, error) {
func (s *ServiceEngine) DeriveLevel1(
ctx context.Context, meta drkey.Level1Meta,
) (drkey.Level1Key, error) {
sv, err := s.GetSecretValue(ctx, drkey.SecretValueMeta{
ProtoId: meta.ProtoId,
Validity: meta.Validity,
Expand Down
5 changes: 1 addition & 4 deletions control/trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,10 @@ func NewTLSCertificateLoader(
}

// NewSigner creates a renewing signer backed by a certificate chain.
func NewSigner(ia addr.IA, db trust.DB, cfgDir string) cstrust.RenewingSigner {
func NewSigner(ctx context.Context, ia addr.IA, db trust.DB, cfgDir string) cstrust.RenewingSigner {
signer := cstrust.RenewingSigner{
SignerGen: newCachingSignerGen(ia, x509.ExtKeyUsageAny, db, cfgDir),
}

ctx, cancelF := context.WithTimeout(context.Background(), time.Second)
defer cancelF()
if _, err := signer.SignerGen.Generate(ctx); err != nil {
log.Debug("Initial signer generation failed", "err", err)
}
Expand Down
3 changes: 2 additions & 1 deletion control/trust_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestNewSigner(t *testing.T) {
require.NoError(t, err)

signer := cs.NewSigner(
context.Background(),
addr.MustParseIA("1-ff00:0:110"),
db,
filepath.Join(dir, "/ISD1/ASff00_0_110"),
Expand All @@ -59,7 +60,7 @@ func testCrypto(t *testing.T) string {

raw, err := os.ReadFile(filepath.Join(dir, "trcs/ISD1-B1-S1.trc"))
require.NoError(t, err)
err = os.WriteFile(filepath.Join(dir, "ISD1/ASff00_0_110/certs/ISD1-B1-S1.trc"), raw, 0666)
err = os.WriteFile(filepath.Join(dir, "ISD1/ASff00_0_110/certs/ISD1-B1-S1.trc"), raw, 0o666)
require.NoError(t, err)
return dir
}
40 changes: 17 additions & 23 deletions daemon/internal/servers/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ type DaemonServer struct {

// Paths serves the paths request.
func (s *DaemonServer) Paths(ctx context.Context,
req *sdpb.PathsRequest) (*sdpb.PathsResponse, error) {

req *sdpb.PathsRequest,
) (*sdpb.PathsResponse, error) {
start := time.Now()
dstI := addr.IA(req.DestinationIsdAs).ISD()
response, err := s.paths(ctx, req)
Expand All @@ -84,8 +84,8 @@ func (s *DaemonServer) Paths(ctx context.Context,
}

func (s *DaemonServer) paths(ctx context.Context,
req *sdpb.PathsRequest) (*sdpb.PathsResponse, error) {

req *sdpb.PathsRequest,
) (*sdpb.PathsResponse, error) {
if _, ok := ctx.Deadline(); !ok {
var cancelF context.CancelFunc
ctx, cancelF = context.WithTimeout(ctx, 10*time.Second)
Expand Down Expand Up @@ -115,7 +115,6 @@ func (s *DaemonServer) fetchPaths(
src, dst addr.IA,
refresh bool,
) ([]snet.Path, error) {

r, err, _ := group.Do(fmt.Sprintf("%s%s%t", src, dst, refresh),
func() (any, error) {
return s.Fetcher.GetPaths(ctx, src, dst, refresh)
Expand Down Expand Up @@ -187,7 +186,6 @@ func pathToPB(path snet.Path) *sdpb.Path {
Notes: meta.Notes,
EpicAuths: epicAuths,
}

}

func linkTypeToPB(lt snet.LinkType) sdpb.LinkType {
Expand All @@ -210,7 +208,7 @@ func (s *DaemonServer) backgroundPaths(origCtx context.Context, src, dst addr.IA
// the original context is large enough no need to spin a background fetch.
return
}
ctx, cancelF := context.WithTimeout(context.Background(), backgroundTimeout)
ctx, cancelF := context.WithTimeout(origCtx, backgroundTimeout)
defer cancelF()
var spanOpts []opentracing.StartSpanOption
if span := opentracing.SpanFromContext(origCtx); span != nil {
Expand Down Expand Up @@ -259,8 +257,8 @@ func (s *DaemonServer) as(ctx context.Context, req *sdpb.ASRequest) (*sdpb.ASRes

// Interfaces serves the interfaces request.
func (s *DaemonServer) Interfaces(ctx context.Context,
req *sdpb.InterfacesRequest) (*sdpb.InterfacesResponse, error) {

req *sdpb.InterfacesRequest,
) (*sdpb.InterfacesResponse, error) {
start := time.Now()
response, err := s.interfaces(ctx, req)
s.Metrics.InterfacesRequests.inc(
Expand All @@ -271,8 +269,8 @@ func (s *DaemonServer) Interfaces(ctx context.Context,
}

func (s *DaemonServer) interfaces(ctx context.Context,
_ *sdpb.InterfacesRequest) (*sdpb.InterfacesResponse, error) {

_ *sdpb.InterfacesRequest,
) (*sdpb.InterfacesResponse, error) {
reply := &sdpb.InterfacesResponse{
Interfaces: make(map[uint64]*sdpb.Interface),
}
Expand All @@ -293,8 +291,8 @@ func (s *DaemonServer) interfaces(ctx context.Context,

// Services serves the services request.
func (s *DaemonServer) Services(ctx context.Context,
req *sdpb.ServicesRequest) (*sdpb.ServicesResponse, error) {

req *sdpb.ServicesRequest,
) (*sdpb.ServicesResponse, error) {
start := time.Now()
respsonse, err := s.services(ctx, req)
s.Metrics.ServicesRequests.inc(
Expand All @@ -305,8 +303,8 @@ func (s *DaemonServer) Services(ctx context.Context,
}

func (s *DaemonServer) services(ctx context.Context,
_ *sdpb.ServicesRequest) (*sdpb.ServicesResponse, error) {

_ *sdpb.ServicesRequest,
) (*sdpb.ServicesResponse, error) {
reply := &sdpb.ServicesResponse{
Services: make(map[string]*sdpb.ListService),
}
Expand All @@ -321,8 +319,8 @@ func (s *DaemonServer) services(ctx context.Context,

// NotifyInterfaceDown notifies the server about an interface that is down.
func (s *DaemonServer) NotifyInterfaceDown(ctx context.Context,
req *sdpb.NotifyInterfaceDownRequest) (*sdpb.NotifyInterfaceDownResponse, error) {

req *sdpb.NotifyInterfaceDownRequest,
) (*sdpb.NotifyInterfaceDownResponse, error) {
start := time.Now()
response, err := s.notifyInterfaceDown(ctx, req)
s.Metrics.InterfaceDownNotifications.inc(
Expand All @@ -333,8 +331,8 @@ func (s *DaemonServer) NotifyInterfaceDown(ctx context.Context,
}

func (s *DaemonServer) notifyInterfaceDown(ctx context.Context,
req *sdpb.NotifyInterfaceDownRequest) (*sdpb.NotifyInterfaceDownResponse, error) {

req *sdpb.NotifyInterfaceDownRequest,
) (*sdpb.NotifyInterfaceDownResponse, error) {
revInfo := &path_mgmt.RevInfo{
RawIsdas: addr.IA(req.IsdAs),
IfID: iface.ID(req.Id),
Expand All @@ -358,7 +356,6 @@ func (s *DaemonServer) PortRange(
_ context.Context,
_ *emptypb.Empty,
) (*sdpb.PortRangeResponse, error) {

startPort, endPort := s.Topology.PortRange()
return &sdpb.PortRangeResponse{
DispatchedPortStart: uint32(startPort),
Expand All @@ -370,7 +367,6 @@ func (s *DaemonServer) DRKeyASHost(
ctx context.Context,
req *pb_daemon.DRKeyASHostRequest,
) (*pb_daemon.DRKeyASHostResponse, error) {

if s.DRKeyClient == nil {
return nil, serrors.New("DRKey is not available")
}
Expand All @@ -395,7 +391,6 @@ func (s *DaemonServer) DRKeyHostAS(
ctx context.Context,
req *pb_daemon.DRKeyHostASRequest,
) (*pb_daemon.DRKeyHostASResponse, error) {

if s.DRKeyClient == nil {
return nil, serrors.New("DRKey is not available")
}
Expand All @@ -420,7 +415,6 @@ func (s *DaemonServer) DRKeyHostHost(
ctx context.Context,
req *pb_daemon.DRKeyHostHostRequest,
) (*pb_daemon.DRKeyHostHostResponse, error) {

if s.DRKeyClient == nil {
return nil, serrors.New("DRKey is not available")
}
Expand Down
Loading

0 comments on commit 429b5e5

Please sign in to comment.