Documentation ¶
Overview ¶
Package bertybridge is the main gomobile entrypoint, used to generate iOS and Android frameworks.
Example ¶
// @FIXME(gfanton): auto relay can occasionally rise data race in some tests, // disabling race for now //go:build !race // +build !race 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/pkg/accounttypes" bridge_svc "berty.tech/berty/v2/go/pkg/bertybridge" "berty.tech/berty/v2/go/pkg/protocoltypes" ) func main() { tmpdir, err := ioutil.TempDir("", "example") checkErr(err) defer os.RemoveAll(tmpdir) // create and start the bridge var b *bertybridge.Bridge { config := bertybridge.NewBridgeConfig() 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) } // set bridge root dir config.SetAppRootDir(tmpdir) b, err = bertybridge.NewBridge(config) checkErr(err) defer b.Close() fmt.Println("[+] initialized.") } args := []string{ "--log.filters=info+:bty*,-*.grpc warn+:*.grpc error+:*", "--log.format=console", "--node.display-name=", "--node.listeners=/ip4/127.0.0.1/tcp/0/grpcws", "--p2p.swarm-listeners=/ip4/127.0.0.1/tcp/0,/ip6/::1/tcp/0", "--p2p.mdns=false", "--p2p.webui-listener=:3000", "--store.dir=" + tmpdir, } var accountID string // create account { // create `CreateAccount` Input input := &accounttypes.CreateAccount_Request{} payload, err := proto.Marshal(input) checkErr(err) // Serialize request in := &bridge_svc.ClientInvokeUnary_Request{ MethodDesc: &bridge_svc.MethodDesc{ Name: "/berty.account.v1.AccountService/CreateAccount", }, Payload: payload, } reqb64, err := encodeProtoMessage(in) checkErr(err) // invoke through bridge client ret, err := b.InvokeBridgeMethod("/berty.bridge.v1.BridgeService/ClientInvokeUnary", reqb64) checkErr(err) // deserialize reply var output bridge_svc.ClientInvokeUnary_Reply err = decodeProtoMessage(ret, &output) checkErr(err) // deserialize reply var res accounttypes.CreateAccount_Reply err = proto.Unmarshal(output.Payload, &res) checkErr(err) accountID = res.GetAccountMetadata().GetAccountID() fmt.Println("[+] account created.") } // open account { // create `CreateAccount` Input input := &accounttypes.OpenAccount_Request{ AccountID: accountID, Args: args, } payload, err := proto.Marshal(input) checkErr(err) // Serialize request in := &bridge_svc.ClientInvokeUnary_Request{ MethodDesc: &bridge_svc.MethodDesc{ Name: "/berty.account.v1.AccountService/OpenAccount", }, Payload: payload, } reqb64, err := encodeProtoMessage(in) checkErr(err) // invoke through bridge client ret, err := b.InvokeBridgeMethod("/berty.bridge.v1.BridgeService/ClientInvokeUnary", reqb64) checkErr(err) // deserialize reply var output bridge_svc.ClientInvokeUnary_Reply err = decodeProtoMessage(ret, &output) checkErr(err) fmt.Println("[+] account opened.") } // check for GRPC listeners { // create `InstanceGetConfiguration` Input input := &accounttypes.GetGRPCListenerAddrs_Request{} payload, err := proto.Marshal(input) checkErr(err) // Serialize request in := &bridge_svc.ClientInvokeUnary_Request{ MethodDesc: &bridge_svc.MethodDesc{ Name: "/berty.account.v1.AccountService/GetGRPCListenerAddrs", }, Payload: payload, } reqb64, err := encodeProtoMessage(in) checkErr(err) // invoke through bridge client ret, err := b.InvokeBridgeMethod("/berty.bridge.v1.BridgeService/ClientInvokeUnary", reqb64) checkErr(err) var output bridge_svc.ClientInvokeUnary_Reply err = decodeProtoMessage(ret, &output) checkErr(err) // deserialize reply var res accounttypes.GetGRPCListenerAddrs_Reply err = proto.Unmarshal(output.Payload, &res) checkErr(err) hasGRPCWeb := false hasGRPCWebSocket := false for _, entry := range res.Entries { switch entry.Proto { case "ip4/tcp/grpcweb": hasGRPCWeb = true case "ip4/tcp/grpcws": hasGRPCWebSocket = true } } fmt.Println("[+] has grpc-web listener: ", hasGRPCWeb) // no, because `--node.listeners` does not contain grpcweb fmt.Println("[+] has websocket listener: ", hasGRPCWebSocket) // yes, because `--node.listeners`` contains grpcws } // make unary call to underlying `BertyMessenger` Service { // create `InstanceGetConfiguration` Input input := &protocoltypes.InstanceGetConfiguration_Request{} payload, err := proto.Marshal(input) checkErr(err) // Serialize request in := &bridge_svc.ClientInvokeUnary_Request{ MethodDesc: &bridge_svc.MethodDesc{ Name: "/berty.protocol.v1.ProtocolService/InstanceGetConfiguration", }, Payload: payload, } reqb64, err := encodeProtoMessage(in) checkErr(err) // invoke through bridge client ret, err := b.InvokeBridgeMethod("/berty.bridge.v1.BridgeService/ClientInvokeUnary", reqb64) checkErr(err) var output bridge_svc.ClientInvokeUnary_Reply err = decodeProtoMessage(ret, &output) checkErr(err) var res protocoltypes.InstanceGetConfiguration_Reply err = proto.Unmarshal(output.Payload, &res) checkErr(err) fmt.Println("[+] has more than one swarm listener:", len(res.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. [+] account created. [+] account opened. [+] has grpc-web listener: false [+] has websocket listener: true [+] has more than one swarm listener: true
Index ¶
- Constants
- func NewNativeDriverCore(core zapcore.Core, enc zapcore.Encoder, nlogger NativeLoggerDriver) zapcore.Core
- type Bridge
- type BridgeConfig
- func (c *BridgeConfig) AppendCLIArg(arg string)
- func (c *BridgeConfig) AppendPreferredLanguage(preferred string)
- func (c *BridgeConfig) SetAppRootDir(rootdir string)
- func (c *BridgeConfig) SetBleDriver(driver ProximityDriver)
- func (c *BridgeConfig) SetKeystoreDriver(d NativeKeystoreDriver)
- func (c *BridgeConfig) SetLifeCycleDriver(lc LifeCycleDriver)
- func (c *BridgeConfig) SetLoggerDriver(dLogger NativeLoggerDriver)
- func (c *BridgeConfig) SetMDNSLocker(driver NativeMDNSLockerDriver)
- func (c *BridgeConfig) SetNBDriver(driver ProximityDriver)
- func (c *BridgeConfig) SetNetDriver(driver NativeNetDriver)
- func (c *BridgeConfig) SetNotificationDriver(driver NotificationDriver)
- func (c *BridgeConfig) SetPreferredLanguages(preferred string)
- func (c *BridgeConfig) SetSharedRootDir(rootdir string)
- type DecryptedPush
- type FormatedPush
- type LifeCycleBackgroundTask
- type LifeCycleDriver
- type LifeCycleHandler
- type LocalNotification
- type NativeKeystoreDriver
- type NativeLoggerDriver
- type NativeMDNSLockerDriver
- type NativeNetDriver
- type NetAddrs
- type NetInterface
- type NetInterfaces
- type NotificationDriver
- type PromiseBlock
- type ProximityDriver
- type ProximityTransport
- type PushConfig
- type PushStandalone
- type RemoteBridge
- type RemoteBridgeConfig
- type ServiceClient
Examples ¶
Constants ¶
View Source
const ( AppStateUnknown int = iota AppStateActive AppStateInactive AppStateBackground )
View Source
const ( NetFlagUp int = iota // interface is up NetFlagBroadcast // interface supports broadcast access capability NetFlagLoopback // interface is a loopback interface NetFlagPointToPoint // interface belongs to a point-to-point link NetFlagMulticast // interface supports multicast access capability )
View Source
const ( ServicePushPayloadKey = pushtypes.ServicePushPayloadKey StorageKeyName = accountutils.StorageKeyName )
Variables ¶
This section is empty.
Functions ¶
func NewNativeDriverCore ¶ added in v2.320.6
Types ¶
type Bridge ¶
type Bridge struct { ServiceClient // contains filtered or unexported fields }
func NewBridge ¶ added in v2.190.1
func NewBridge(config *BridgeConfig) (*Bridge, error)
func (*Bridge) HandleState ¶ added in v2.190.1
func (*Bridge) HandleTask ¶ added in v2.190.1
func (b *Bridge) HandleTask() LifeCycleBackgroundTask
func (*Bridge) PushDecrypt ¶ added in v2.319.0
func (b *Bridge) PushDecrypt(inputB64 string) (*FormatedPush, error)
func (*Bridge) WillTerminate ¶ added in v2.190.1
func (b *Bridge) WillTerminate()
type BridgeConfig ¶ added in v2.435.0
type BridgeConfig struct { CLIArgs []string `json:"cliArgs"` AppRootDirPath string `json:"appRootDir"` // contains filtered or unexported fields }
Config is used to build a bertybridge configuration using only simple types or types returned by the bertybridge package.
func NewBridgeConfig ¶ added in v2.435.0
func NewBridgeConfig() *BridgeConfig
func (*BridgeConfig) AppendCLIArg ¶ added in v2.435.0
func (c *BridgeConfig) AppendCLIArg(arg string)
func (*BridgeConfig) AppendPreferredLanguage ¶ added in v2.435.0
func (c *BridgeConfig) AppendPreferredLanguage(preferred string)
func (*BridgeConfig) SetAppRootDir ¶ added in v2.435.0
func (c *BridgeConfig) SetAppRootDir(rootdir string)
func (*BridgeConfig) SetBleDriver ¶ added in v2.435.0
func (c *BridgeConfig) SetBleDriver(driver ProximityDriver)
func (*BridgeConfig) SetKeystoreDriver ¶ added in v2.435.0
func (c *BridgeConfig) SetKeystoreDriver(d NativeKeystoreDriver)
func (*BridgeConfig) SetLifeCycleDriver ¶ added in v2.435.0
func (c *BridgeConfig) SetLifeCycleDriver(lc LifeCycleDriver)
func (*BridgeConfig) SetLoggerDriver ¶ added in v2.435.0
func (c *BridgeConfig) SetLoggerDriver(dLogger NativeLoggerDriver)
func (*BridgeConfig) SetMDNSLocker ¶ added in v2.435.0
func (c *BridgeConfig) SetMDNSLocker(driver NativeMDNSLockerDriver)
func (*BridgeConfig) SetNBDriver ¶ added in v2.435.0
func (c *BridgeConfig) SetNBDriver(driver ProximityDriver)
func (*BridgeConfig) SetNetDriver ¶ added in v2.435.0
func (c *BridgeConfig) SetNetDriver(driver NativeNetDriver)
func (*BridgeConfig) SetNotificationDriver ¶ added in v2.435.0
func (c *BridgeConfig) SetNotificationDriver(driver NotificationDriver)
func (*BridgeConfig) SetPreferredLanguages ¶ added in v2.435.0
func (c *BridgeConfig) SetPreferredLanguages(preferred string)
func (*BridgeConfig) SetSharedRootDir ¶ added in v2.435.0
func (c *BridgeConfig) SetSharedRootDir(rootdir string)
type DecryptedPush ¶ added in v2.319.0
type DecryptedPush pushtypes.DecryptedPush
type FormatedPush ¶ added in v2.327.0
type FormatedPush pushtypes.FormatedPush
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 NativeKeystoreDriver ¶ added in v2.313.0
type NativeKeystoreDriver interface { accountutils.NativeKeystore }
type NativeLoggerDriver ¶
type NativeMDNSLockerDriver ¶ added in v2.337.0
type NativeMDNSLockerDriver interface { Lock() Unlock() }
type NativeNetDriver ¶ added in v2.337.0
type NativeNetDriver interface { InterfaceAddrs() (*NetAddrs, error) Interfaces() (*NetInterfaces, error) }
type NetAddrs ¶ added in v2.337.0
type NetAddrs struct {
// contains filtered or unexported fields
}
func NewNetAddrs ¶ added in v2.337.0
func NewNetAddrs() *NetAddrs
func (*NetAddrs) AppendAddr ¶ added in v2.337.0
type NetInterface ¶ added in v2.346.0
type NetInterface struct { Index int // positive integer that starts at one, zero is never used MTU int // maximum transmission unit Name string // e.g., "en0", "lo0", "eth0.100" Addrs *NetAddrs // InterfaceAddresses // contains filtered or unexported fields }
func (*NetInterface) AddFlag ¶ added in v2.346.0
func (n *NetInterface) AddFlag(flag int) (err error)
func (*NetInterface) CopyHardwareAddr ¶ added in v2.346.0
func (n *NetInterface) CopyHardwareAddr(addr []byte)
func (*NetInterface) Interface ¶ added in v2.346.0
func (n *NetInterface) Interface() net.Interface
type NetInterfaces ¶ added in v2.346.0
type NetInterfaces struct {
// contains filtered or unexported fields
}
func (*NetInterfaces) Append ¶ added in v2.346.0
func (n *NetInterfaces) Append(i *NetInterface)
func (*NetInterfaces) Interfaces ¶ added in v2.346.0
func (n *NetInterfaces) Interfaces() []net.Interface
type NotificationDriver ¶ added in v2.134.1
type NotificationDriver interface {
Post(notif *LocalNotification) error
}
type PromiseBlock ¶ added in v2.121.0
type ProximityDriver ¶ added in v2.296.0
type ProximityDriver interface { proximity.ProximityDriver }
type ProximityTransport ¶ added in v2.260.0
type ProximityTransport interface { proximity.ProximityTransport }
func GetProximityTransport ¶ added in v2.260.0
func GetProximityTransport(protocolName string) ProximityTransport
type PushConfig ¶ added in v2.327.0
type PushConfig struct {
// contains filtered or unexported fields
}
func NewPushConfig ¶ added in v2.327.0
func NewPushConfig() *PushConfig
func (*PushConfig) SetDriverLogger ¶ added in v2.327.0
func (c *PushConfig) SetDriverLogger(logger NativeLoggerDriver)
func (*PushConfig) SetPreferredLanguages ¶ added in v2.327.0
func (c *PushConfig) SetPreferredLanguages(lang string)
type PushStandalone ¶ added in v2.327.0
type PushStandalone struct {
// contains filtered or unexported fields
}
func NewPushStandalone ¶ added in v2.327.0
func NewPushStandalone(c *PushConfig) *PushStandalone
func (*PushStandalone) Decrypt ¶ added in v2.327.0
func (s *PushStandalone) Decrypt(rootDir string, inputB64 string, ks NativeKeystoreDriver) (*FormatedPush, error)
type RemoteBridge ¶ added in v2.435.0
type RemoteBridge struct { ServiceClient // contains filtered or unexported fields }
func NewRemoteBridge ¶ added in v2.435.0
func NewRemoteBridge(address string, config *RemoteBridgeConfig) (*RemoteBridge, error)
func (*RemoteBridge) Close ¶ added in v2.435.0
func (b *RemoteBridge) Close() error
func (*RemoteBridge) ConnectService ¶ added in v2.435.0
func (b *RemoteBridge) ConnectService(serviceName string, address string) error
type RemoteBridgeConfig ¶ added in v2.435.0
type RemoteBridgeConfig struct {
// contains filtered or unexported fields
}
Config is used to build a bertybridge configuration using only simple types or types returned by the bertybridge package.
func NewRemoteBridgeConfig ¶ added in v2.435.0
func NewRemoteBridgeConfig() *RemoteBridgeConfig
func (*RemoteBridgeConfig) SetLoggerDriver ¶ added in v2.435.0
func (c *RemoteBridgeConfig) SetLoggerDriver(dLogger NativeLoggerDriver)
type ServiceClient ¶ added in v2.435.0
type ServiceClient interface { InvokeBridgeMethodWithPromiseBlock(promise PromiseBlock, method string, b64message string) InvokeBridgeMethod(method string, b64message string) (string, error) }
func NewServiceClient ¶ added in v2.435.0
func NewServiceClient(cl *grpcutil.LazyClient) ServiceClient
Click to show internal directories.
Click to hide internal directories.