-
Notifications
You must be signed in to change notification settings - Fork 18
integrate mycelium messaging subsystem #2570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Omarabdul3ziz
wants to merge
4
commits into
main
Choose a base branch
from
main_myceliumMsg
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,81 @@ | ||||||
package myceliumrx | ||||||
|
||||||
import ( | ||||||
"crypto/ed25519" | ||||||
"fmt" | ||||||
|
||||||
"github.com/pkg/errors" | ||||||
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go" | ||||||
"github.com/threefoldtech/tfgrid-sdk-go/messenger" | ||||||
"github.com/threefoldtech/zosbase/pkg/api" | ||||||
"github.com/threefoldtech/zosbase/pkg/api/jsonrpc" | ||||||
"github.com/threefoldtech/zosbase/pkg/environment" | ||||||
"github.com/threefoldtech/zosbase/pkg/stubs" | ||||||
"github.com/urfave/cli/v2" | ||||||
|
||||||
"github.com/threefoldtech/zbus" | ||||||
) | ||||||
|
||||||
// Module is entry point for module | ||||||
var Module cli.Command = cli.Command{ | ||||||
Name: "myceliumrx", | ||||||
Usage: "handles mycelium messages", | ||||||
Flags: []cli.Flag{ | ||||||
&cli.StringFlag{ | ||||||
Name: "broker", | ||||||
Usage: "connection string to the message `BROKER`", | ||||||
Value: "unix:///var/run/redis.sock", | ||||||
}, | ||||||
}, | ||||||
Action: action, | ||||||
} | ||||||
|
||||||
func action(cli *cli.Context) error { | ||||||
var broker string = cli.String("broker") | ||||||
client, err := zbus.NewRedisClient(broker) | ||||||
if err != nil { | ||||||
return errors.Wrap(err, "failed to connect to zbus broker") | ||||||
} | ||||||
|
||||||
a, err := api.NewAPI(client, broker, "full") | ||||||
if err != nil { | ||||||
return errors.Wrap(err, "failed to create api") | ||||||
} | ||||||
|
||||||
idStub := stubs.NewIdentityManagerStub(client) | ||||||
sk := ed25519.PrivateKey(idStub.PrivateKey(cli.Context)) | ||||||
id, err := substrate.NewIdentityFromEd25519Key(sk) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
man, err := environment.GetSubstrate() | ||||||
if err != nil { | ||||||
return fmt.Errorf("failed to get substrate manager: %w", err) | ||||||
} | ||||||
ctx := cli.Context | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assignment 'ctx := cli.Context' is incorrect as cli.Context is a type instead of the actual context value. The proper pattern is to call the context getter method (e.g., cli.Context()) to retrieve the running context.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
msgr, err := messenger.NewMessenger( | ||||||
messenger.WithEnableTwinIdentity(false), | ||||||
messenger.WithSubstrateManager(man), | ||||||
messenger.WithIdentity(id), | ||||||
) | ||||||
|
||||||
if err != nil { | ||||||
return fmt.Errorf("failed to create substrate manager: %w", err) | ||||||
} | ||||||
defer msgr.Close() | ||||||
|
||||||
server := messenger.NewJSONRPCServer(msgr) | ||||||
|
||||||
hdrs := jsonrpc.NewRpcHandler(a) | ||||||
jsonrpc.RegisterHandlers(server, hdrs) | ||||||
|
||||||
if err := server.Start(ctx); err != nil { | ||||||
return fmt.Errorf("failed to start server: %w", err) | ||||||
} | ||||||
|
||||||
// block forever | ||||||
<-ctx.Done() | ||||||
return nil | ||||||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
exec: ip netns exec ndmz myceliumrx --broker unix:///var/run/redis.sock | ||
after: | ||
- networkd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../bin/zos |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../etc/zinit/myceliumrx.yaml |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function call uses 'cli.Context' as if it were a context instance. It should likely call the method (for example, cli.Context()) to obtain the proper context object required by idStub.PrivateKey.
Copilot uses AI. Check for mistakes.