diff --git a/go.mod b/go.mod index a6da459b..f7217819 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,7 @@ require ( github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 github.com/vishvananda/netlink v1.2.1-beta.2 - github.com/webmeshproj/api v0.11.4-0.20231109201546-44726ffeea69 + github.com/webmeshproj/api v0.11.4-0.20231109225108-67650c62010a golang.org/x/crypto v0.14.0 golang.org/x/exp v0.0.0-20231006140011-7918f672742d golang.org/x/net v0.17.0 diff --git a/go.sum b/go.sum index 321c6a7d..fc08ce6d 100644 --- a/go.sum +++ b/go.sum @@ -1576,6 +1576,8 @@ github.com/webmeshproj/api v0.11.2 h1:121MlNlwWNU2II3gF2v9I/x342s/yBKvDs+JqmjKDf github.com/webmeshproj/api v0.11.2/go.mod h1:xuYk93HM4aZWWlTh96Z2nIg1YhqcRG36nOfcifzHeM4= github.com/webmeshproj/api v0.11.4-0.20231109201546-44726ffeea69 h1:lnpiABZ5U10GCRacgmvUK9tCuBLTJqQg0vWmm4r8N6c= github.com/webmeshproj/api v0.11.4-0.20231109201546-44726ffeea69/go.mod h1:xuYk93HM4aZWWlTh96Z2nIg1YhqcRG36nOfcifzHeM4= +github.com/webmeshproj/api v0.11.4-0.20231109225108-67650c62010a h1:uCOjrwdx5/0T527YDA3v1Rtnd7Xy49847j0pkrnLKUo= +github.com/webmeshproj/api v0.11.4-0.20231109225108-67650c62010a/go.mod h1:xuYk93HM4aZWWlTh96Z2nIg1YhqcRG36nOfcifzHeM4= github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k= github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= diff --git a/pkg/cmd/daemoncmd/profiles.go b/pkg/cmd/daemoncmd/profiles.go index d22f8343..1567ec98 100644 --- a/pkg/cmd/daemoncmd/profiles.go +++ b/pkg/cmd/daemoncmd/profiles.go @@ -49,6 +49,11 @@ func (id ProfileID) Bytes() []byte { return []byte(id) } +// IsEmpty returns whether the profile ID is empty. +func (id ProfileID) IsEmpty() bool { + return id == "" +} + var profilesPrefix = []byte("profiles") // StorageKey returns the storage key for the profile ID. diff --git a/pkg/cmd/daemoncmd/server.go b/pkg/cmd/daemoncmd/server.go index a5468882..0a9fd190 100644 --- a/pkg/cmd/daemoncmd/server.go +++ b/pkg/cmd/daemoncmd/server.go @@ -29,6 +29,7 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" "github.com/webmeshproj/webmesh/pkg/context" + "github.com/webmeshproj/webmesh/pkg/crypto" "github.com/webmeshproj/webmesh/pkg/storage/errors" "github.com/webmeshproj/webmesh/pkg/storage/rpcsrv" "github.com/webmeshproj/webmesh/pkg/version" @@ -164,11 +165,19 @@ func (app *AppDaemon) PutConnection(ctx context.Context, req *v1.PutConnectionRe if err != nil { return nil, newInvalidError(err) } - err = app.connmgr.Profiles().Put(ctx, ProfileID(req.GetId()), Profile{req.GetParameters()}) + profileID := ProfileID(req.GetId()) + if profileID.IsEmpty() { + id, err := crypto.NewRandomID() + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to generate connection ID: %v", err) + } + profileID = ProfileID(id) + } + err = app.connmgr.Profiles().Put(ctx, profileID, Profile{req.GetParameters()}) if err != nil { return nil, status.Errorf(codes.Internal, "failed to store connection: %v", err) } - return &v1.PutConnectionResponse{}, nil + return &v1.PutConnectionResponse{Id: profileID.String()}, nil } func (app *AppDaemon) GetConnection(ctx context.Context, req *v1.GetConnectionRequest) (*v1.GetConnectionResponse, error) {