Documentation ¶
Overview ¶
Package bertybridge is the main gomobile entrypoint, used to generate iOS and Android frameworks.
Example ¶
package main import ( "encoding/base64" "fmt" "io/ioutil" "os" "github.com/gogo/protobuf/proto" "berty.tech/berty/v2/go/framework/bertybridge" "berty.tech/berty/v2/go/framework/bertybridge/internal/bridgepb" "berty.tech/berty/v2/go/pkg/bertytypes" ) func main() { tmpdir, err := ioutil.TempDir("", "example") checkErr(err) defer os.RemoveAll(tmpdir) // create and start the bridge var bridge *bertybridge.Bridge { config := bertybridge.NewConfig() { if false { // disabled in example, but not commented to be sure that compiler performs various checks config.SetLifeCycleDriver(nil) config.SetLoggerDriver(nil) config.SetNotificationDriver(nil) } config.AppendCLIArg("--log.filters=info+:bty*,-*.grpc warn+:*.grpc error+:*") config.AppendCLIArg("--log.format=console") config.AppendCLIArg("--node.display-name=") config.AppendCLIArg("--node.listeners=/ip4/127.0.0.1/tcp/0/grpcws") config.AppendCLIArg("--p2p.swarm-listeners=/ip4/0.0.0.0/tcp/0,/ip6/0.0.0.0/tcp/0") config.AppendCLIArg("--p2p.local-discovery=false") config.AppendCLIArg("--p2p.webui-listener=:3000") config.AppendCLIArg("--store.dir=" + tmpdir) } bridge, err = bertybridge.NewBridge(config) checkErr(err) defer bridge.Close() fmt.Println("[+] initialized.") } fmt.Println("[+] has grpc-web listener: ", bridge.GRPCWebListenerAddr() != "") // no, because `--node.listeners` does not contain grpcweb fmt.Println("[+] has websocket listener: ", bridge.GRPCWebSocketListenerAddr() != "") // yes, because `--node.listeners`` contains grpcws // unary client call { // create `InstanceGetConfiguration` Input input := &bertytypes.InstanceGetConfiguration_Request{} payload, err := proto.Marshal(input) checkErr(err) // Serialize request req := &bridgepb.ClientInvokeUnary_Request{ MethodDesc: &bridgepb.MethodDesc{ Name: "/berty.protocol.v1.ProtocolService/InstanceGetConfiguration", IsClientStream: false, IsServerStream: false, }, Payload: payload, } reqb64, err := encodeProtoMessage(req) checkErr(err) // invoke through bridge client ret, err := bridge.InvokeBridgeMethod("/berty.bridge.v1.BridgeService/ClientInvokeUnary", reqb64) checkErr(err) // deserialize reply var res bridgepb.ClientInvokeUnary_Reply err = decodeProtoMessage(ret, &res) checkErr(err) // check for error if res.Error != nil { fmt.Fprintf(os.Stderr, "bridge client error: `[%s] %s`\n", res.Error.ErrorCode.String(), res.Error.Message) panic(err) } // deserialize output var output bertytypes.InstanceGetConfiguration_Reply err = proto.Unmarshal(res.Payload, &output) checkErr(err) fmt.Println("[+] has more than one swarm listener:", len(output.Listeners) > 1) // log.Println("ret", godev.PrettyJSON(output)) } } func checkErr(err error) { if err != nil { fmt.Fprintf(os.Stderr, "%+v\n", err) panic(err) } } func decodeProtoMessage(input string, output proto.Message) error { dec, err := base64.StdEncoding.DecodeString(input) if err != nil { return err } return proto.Unmarshal(dec, output) } func encodeProtoMessage(input proto.Message) (string, error) { data, err := proto.Marshal(input) if err != nil { return "", err } return base64.StdEncoding.EncodeToString(data), nil }
Output: [+] initialized. [+] has grpc-web listener: false [+] has websocket listener: true [+] has more than one swarm listener: true
Index ¶
- Constants
- type Bridge
- func (b *Bridge) Close() error
- func (b *Bridge) GRPCWebListenerAddr() string
- func (b *Bridge) GRPCWebSocketListenerAddr() string
- func (b *Bridge) HandleState(appstate int)
- func (b *Bridge) HandleTask() LifeCycleBackgroundTask
- func (b *Bridge) InvokeBridgeMethod(method string, b64message string) (string, error)
- func (b *Bridge) InvokeBridgeMethodWithPromiseBlock(promise PromiseBlock, method string, b64message string)
- func (b *Bridge) WillTerminate()
- type Config
- type LifeCycleBackgroundTask
- type LifeCycleDriver
- type LifeCycleHandler
- type LocalNotification
- type NativeLoggerDriver
- type NotificationDriver
- type PromiseBlock
Examples ¶
Constants ¶
View Source
const ( AppStateUnknown int = iota AppStateActive AppStateInactive AppStateBackground )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bridge ¶
type Bridge struct {
// contains filtered or unexported fields
}
func (*Bridge) GRPCWebListenerAddr ¶
func (b *Bridge) GRPCListenerAddr() string { return b.getGRPCAddrFor("ip4/tcp/grpc") }
func (*Bridge) GRPCWebSocketListenerAddr ¶
func (*Bridge) HandleState ¶ added in v2.190.1
func (*Bridge) HandleTask ¶ added in v2.190.1
func (b *Bridge) HandleTask() LifeCycleBackgroundTask
func (*Bridge) InvokeBridgeMethod ¶ added in v2.121.0
func (*Bridge) InvokeBridgeMethodWithPromiseBlock ¶ added in v2.121.0
func (b *Bridge) InvokeBridgeMethodWithPromiseBlock(promise PromiseBlock, method string, b64message string)
func (*Bridge) WillTerminate ¶ added in v2.190.1
func (b *Bridge) WillTerminate()
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is used to build a bridge configuration using only simple types or types returned by the bridge package.
func (*Config) AppendCLIArg ¶ added in v2.190.1
func (*Config) SetLifeCycleDriver ¶ added in v2.190.1
func (c *Config) SetLifeCycleDriver(lc LifeCycleDriver)
func (*Config) SetLoggerDriver ¶ added in v2.190.1
func (c *Config) SetLoggerDriver(dLogger NativeLoggerDriver)
func (*Config) SetNotificationDriver ¶ added in v2.190.1
func (c *Config) SetNotificationDriver(driver NotificationDriver)
type LifeCycleBackgroundTask ¶ added in v2.124.0
type LifeCycleBackgroundTask interface { Execute() (success bool) Cancel() }
type LifeCycleDriver ¶ added in v2.124.0
type LifeCycleDriver interface { GetCurrentState() int RegisterHandler(handler LifeCycleHandler) }
type LifeCycleHandler ¶ added in v2.124.0
type LifeCycleHandler interface { HandleState(appstate int) HandleTask() LifeCycleBackgroundTask WillTerminate() }
type LocalNotification ¶ added in v2.134.1
type NativeLoggerDriver ¶
type NotificationDriver ¶ added in v2.134.1
type NotificationDriver interface {
Post(notif *LocalNotification) error
}
type PromiseBlock ¶ added in v2.121.0
Source Files ¶
Click to show internal directories.
Click to hide internal directories.