Documentation
¶
Overview ¶
Package minoch is an implementation of Mino that is using channels and a local manager to exchange messages.
Because it is using only Go channels to communicate, this implementation can only be used by multiple instances in the same process. Its usage is purely to simplify the writing of tests, therefore it also provides some additionnal functionalities like filters.
A filter is called for any message incoming and it will determine if the instance should drop the message.
Documentation Last Review: 06.10.2020
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddressFactory ¶
AddressFactory is a factory to deserialize Minoch addresses.
- implements mino.AddressFactory
type Envelope ¶
type Envelope struct {
// contains filtered or unexported fields
}
Envelope is the wrapper to send messages through streams.
type Filter ¶
Filter is a function called for any request to an RPC which will drop it if it returns false.
type Minoch ¶
Minoch is an implementation of the Mino interface using channels. Each instance must have a unique string assigned to it.
- implements mino.Mino
func MustCreate ¶
MustCreate creates a new minoch instance and panic if the identifier is refused by the manager.
func (*Minoch) AddFilter ¶
AddFilter adds the filter to all of the RPCs. This must be called before receiving requests.
func (*Minoch) CreateRPC ¶
CreateRPC creates an RPC that can send to and receive from the unique path.
func (*Minoch) GetAddress ¶
GetAddress implements mino.Mino. It returns the address that other participants should use to contact this instance.
func (*Minoch) GetAddressFactory ¶
func (m *Minoch) GetAddressFactory() mino.AddressFactory
GetAddressFactory implements mino.Mino. It returns the address factory.
type RPC ¶
type RPC struct {
// contains filtered or unexported fields
}
RPC implements a remote procedure call that is calling its peers using the channels registered by the manager.
- implements mino.RPC
func (RPC) Call ¶
func (c RPC) Call(ctx context.Context, req serde.Message, players mino.Players) (<-chan mino.Response, error)
Call implements mino.RPC. It sends the message to all participants and gathers their replies. The context is ignored in the scope of channel communication as there is no blocking I/O. The response channel will receive n responses for n players and be closed eventually.
Example ¶
package main import ( "context" "fmt" "go.dedis.ch/dela/mino" "go.dedis.ch/dela/serde" ) func main() { manager := NewManager() minoA := MustCreate(manager, "A").WithSegment("example") minoB := MustCreate(manager, "B").WithSegment("example") rpcA := mino.MustCreateRPC(minoA, "hello", exampleHandler{}, exampleFactory{}) mino.MustCreateRPC(minoB, "hello", exampleHandler{}, exampleFactory{}) roster := mino.NewAddresses(minoA.GetAddress(), minoB.GetAddress()) ctx, cancel := context.WithCancel(context.Background()) defer cancel() msg := exampleMessage{value: "Hello World!"} resps, err := rpcA.Call(ctx, msg, roster) if err != nil { panic("call failed: " + err.Error()) } for resp := range resps { reply, err := resp.GetMessageOrError() if err != nil { panic("error in response: " + err.Error()) } fmt.Println(reply.(exampleMessage).value) } } // exampleHandler is an RPC handler example. // // - implements mino.Handler type exampleHandler struct { mino.UnsupportedHandler } // Process implements mino.Handler. It returns the message received. func (exampleHandler) Process(req mino.Request) (serde.Message, error) { return req.Message, nil } // exampleMessage is an example of a message. // // - implements serde.Message type exampleMessage struct { value string } // Serialize implements serde.Message. It returns the value contained in the // message. func (m exampleMessage) Serialize(serde.Context) ([]byte, error) { return []byte(m.value), nil } // exampleFactory is an example of a factory. // // - implements serde.Factory type exampleFactory struct{} // Deserialize implements serde.Factory. It returns the message using data as // the inner value. func (exampleFactory) Deserialize(ctx serde.Context, data []byte) (serde.Message, error) { return exampleMessage{value: string(data)}, nil }
Output: Hello World! Hello World!