Skip to content

Commit

Permalink
feat: return connection IDs on PutConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
tinyzimmer committed Nov 9, 2023
1 parent 59976b2 commit a0c4ab3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
5 changes: 5 additions & 0 deletions pkg/cmd/daemoncmd/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 11 additions & 2 deletions pkg/cmd/daemoncmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a0c4ab3

Please sign in to comment.