Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command uint32
A p2p command
func (Command) Send ¶
Send returns the command response and an error, used to send data over p2p on given protocol and command.
Example ¶
package main import ( "fmt" symbols "bitbucket.org/taubyte/go-sdk-symbols/p2p/node" "bitbucket.org/taubyte/go-sdk/event" "bitbucket.org/taubyte/go-sdk/p2p/node" ) func main() { // Mocking the calls to the vm for usage in tests and playground m := symbols.MockData{ Protocol: "/test/v1", Command: "someCommand", SendResponse: []byte("Hello from the other side!"), }.Mock() service := node.New(m.Protocol) // Instantiate a command `someCommand` to protocol `/test/v1` command, err := service.Command(m.Command) if err != nil { return } // Send the command with data []byte("Hello, world!") response, err := command.Send([]byte("Hello, world!")) if err != nil { return } // A function representing the call executed by the above command _ = func(e event.Event) uint32 { p2pEvent, err := e.P2P() if err != nil { return 1 } data, err := p2pEvent.Data() if err != nil { return 1 } if string(data) == "Hello, world!" { p2pEvent.Write([]byte("Hello from the other side!")) return 0 } return 1 } fmt.Println(string(response)) }
Output: Hello from the other side!
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
A p2p service with on a given protocol
func (*Service) Command ¶
Command returns a p2p Command and an error Used for sending a given command on a protocol
Example ¶
package main import ( "fmt" symbols "bitbucket.org/taubyte/go-sdk-symbols/p2p/node" "bitbucket.org/taubyte/go-sdk/p2p/node" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.MockData{ Protocol: "/test/v1", Command: "someCommand", CommandId: 5, }.Mock() service := node.New("/test/v1") // Instantiate a command `someCommand` to protocol `/test/v1` command, err := service.Command("someCommand") if err != nil { return } fmt.Println(command) }
Output: 5
func (*Service) Listen ¶
Listen returns the projectProtocol and an error. Asks a node to listen on a protocol, and returns the protocol the node is set to listen on.
Example ¶
package main import ( "fmt" symbols "bitbucket.org/taubyte/go-sdk-symbols/p2p/node" "bitbucket.org/taubyte/go-sdk/p2p/node" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.MockData{ ListenHash: "QmZjBpQzR", ListenProtocol: "/test/v1", }.Mock() // Instantiate a service with protocol `/test/v1` service := node.New("/test/v1") listenProtocol, err := service.Listen() if err != nil { return } fmt.Println(listenProtocol) }
Output: /QmZjBpQzR/test/v1
func (*Service) Protocol ¶
Returns the protocol of a given service
Example ¶
package main import ( "fmt" symbols "bitbucket.org/taubyte/go-sdk-symbols/p2p/node" "bitbucket.org/taubyte/go-sdk/p2p/node" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.MockData{ Protocol: "/test/v1", }.Mock() service := node.New("/test/v1") fmt.Println(service.Protocol()) }
Output: /test/v1
Click to show internal directories.
Click to hide internal directories.