weshnet

package module
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2023 License: Apache-2.0, MIT Imports: 104 Imported by: 5

README

Wesh Network Toolkit

go.dev reference

The Wesh network toolkit lets your application use the Wesh protocol to support privacy-based, off-grid, peer-to-peer communication. Wesh powers Berty Messenger, and now you can use the Wesh network toolkit directly.

Your application interfaces to Wesh based on gRPC. So even though the core Wesh code is written in Go, Wesh works with your application written in Go, Python or other languages supported by gRPC.

For details, see the Wesh website at https://wesh.network . The website includes blog tutorials which introduce you to Wesh and walk you through some example applications and background of the Wesh protocol.

Usage

import "berty.tech/weshnet"

Online API documentation is at https://buf.build/berty/weshnet .

Get the code

To get the code and build, see the file INSTALL.md.

Feedback

For bug reports, feature requests or questions, please open a GitHub issue.

Documentation

Overview

Package weshnet contains code for integrating the Berty protocol in your project.

See https://berty.tech/protocol for more information.

Index

Examples

Constants

View Source
const (
	NamespaceOrbitDBDatastore = "orbitdb_datastore"
	NamespaceOrbitDBDirectory = "orbitdb"
	NamespaceIPFSDatastore    = "ipfs_datastore"
)
View Source
const (
	TyberEventTinderPeerFound  = "Tinder peer found"
	TyberEventTinderPeerJoined = "Tinder peer joined"
	TyberEventTinderPeerLeft   = "Tinder peer left"
)
View Source
const ClientBufferSize = 4 * 1024 * 1024
View Source
const CurrentGroupVersion = 1
View Source
const InMemoryDir = ":memory:"

Variables

View Source
var InMemoryDirectory = cacheleveldown.InMemoryDirectory

Functions

func ConnectAll

func ConnectAll(t testing.TB, m libp2p_mocknet.Mocknet)

ConnectAll peers between themselves

func ConnectInLine

func ConnectInLine(t testing.TB, m libp2p_mocknet.Mocknet)

func CreateMultiMemberGroupInstance

func CreateMultiMemberGroupInstance(ctx context.Context, t *testing.T, tps ...*TestingProtocol) *protocoltypes.Group

func CreatePeersWithGroupTest

func CreatePeersWithGroupTest(ctx context.Context, t testing.TB, pathBase string, memberCount int, deviceCount int) ([]*mockedPeer, crypto.PrivKey, func())

func DefaultOrbitDBOptions

func DefaultOrbitDBOptions(g *protocoltypes.Group, options *orbitdb.CreateDBOptions, keystore *BertySignedKeyStore, storeType string, groupOpenMode GroupOpenMode) (*orbitdb.CreateDBOptions, error)

func FilterGroupForReplication

func FilterGroupForReplication(m *protocoltypes.Group) (*protocoltypes.Group, error)

func GetRootDatastoreForPath

func GetRootDatastoreForPath(dir string, key []byte, salt []byte, logger *zap.Logger) (datastore.Batching, error)

func MetadataStoreSendSecret

func MetadataStoreSendSecret(ctx context.Context, m *MetadataStore, g *protocoltypes.Group, md secretstore.OwnMemberDevice, memberPK crypto.PubKey, encryptedSecret []byte) (operation.Operation, error)

func NewGroupMultiMember

func NewGroupMultiMember() (*protocoltypes.Group, crypto.PrivKey, error)

NewGroupMultiMember creates a new Group object and an invitation to be used by the first member of the group

func NewOrbitDatastoreCache

func NewOrbitDatastoreCache(ds datastore.Batching) cache.Interface

func NewSimpleAccessController

NewSimpleAccessController Returns a non configurable access controller

func RestoreAccountExport

func RestoreAccountExport(ctx context.Context, reader io.Reader, coreAPI ipfs_interface.CoreAPI, odb *WeshOrbitDB, logger *zap.Logger, handlers ...RestoreAccountHandler) error

Types

type AccountContact

type AccountContact struct {
	// contains filtered or unexported fields
}

type AccountKeys

type AccountKeys interface {
	AccountPrivKey() (crypto.PrivKey, error)
	AccountProofPrivKey() (crypto.PrivKey, error)
	DevicePrivKey() (crypto.PrivKey, error)
	ContactGroupPrivKey(pk crypto.PubKey) (crypto.PrivKey, error)
	MemberDeviceForGroup(g *protocoltypes.Group) (secretstore.OwnMemberDevice, error)
}

type BertySignedKeyStore

type BertySignedKeyStore struct {
	sync.Map
}

func (*BertySignedKeyStore) CreateKey

func (s *BertySignedKeyStore) CreateKey(ctx context.Context, id string) (crypto.PrivKey, error)

func (*BertySignedKeyStore) GetKey

func (*BertySignedKeyStore) HasKey

func (s *BertySignedKeyStore) HasKey(ctx context.Context, id string) (bool, error)

func (*BertySignedKeyStore) SetKey

func (s *BertySignedKeyStore) SetKey(pk crypto.PrivKey) error

func (*BertySignedKeyStore) Sign

func (s *BertySignedKeyStore) Sign(privKey crypto.PrivKey, bytes []byte) ([]byte, error)

func (*BertySignedKeyStore) Verify

func (s *BertySignedKeyStore) Verify(signature []byte, publicKey crypto.PubKey, data []byte) error

type ConnectTestingProtocolFunc

type ConnectTestingProtocolFunc func(testing.TB, libp2p_mocknet.Mocknet)

Connect Peers Helper

type ConnectednessManager

type ConnectednessManager struct {
	// contains filtered or unexported fields
}

func NewConnectednessManager

func NewConnectednessManager() *ConnectednessManager

func (*ConnectednessManager) AssociatePeer

func (m *ConnectednessManager) AssociatePeer(group string, peer peer.ID)

AssociatePeer associate a peer to a group

func (*ConnectednessManager) UpdateState

func (m *ConnectednessManager) UpdateState(peer peer.ID, update ConnectednessType)

UpdateState update peer current connectedness state

func (*ConnectednessManager) WaitForConnectednessChange

func (m *ConnectednessManager) WaitForConnectednessChange(ctx context.Context, gkey string, current PeersConnectedness) ([]peer.ID, bool)

WaitForConnectednessChange wait until the given `current` peers status differ from `local` peers state

type ConnectednessType

type ConnectednessType int
const (
	ConnectednessTypeDisconnected ConnectednessType = iota
	ConnectednessTypeReconnecting
	ConnectednessTypeConnected
)

type ConnectednessUpdate

type ConnectednessUpdate struct {
	Peer   peer.ID
	Status ConnectednessType
}

type EventMetadataReceived

type EventMetadataReceived struct {
	MetaEvent *protocoltypes.GroupMetadataEvent
	Event     proto.Message
}

type GroupContext

type GroupContext struct {
	// contains filtered or unexported fields
}

func NewContextGroup

func NewContextGroup(group *protocoltypes.Group, metadataStore *MetadataStore, messageStore *MessageStore, secretStore secretstore.SecretStore, memberDevice secretstore.OwnMemberDevice, logger *zap.Logger) *GroupContext

func (*GroupContext) ActivateGroupContext

func (gc *GroupContext) ActivateGroupContext(contact crypto.PubKey) error

func (*GroupContext) Close

func (gc *GroupContext) Close() error

func (*GroupContext) DevicePubKey

func (gc *GroupContext) DevicePubKey() crypto.PubKey

func (*GroupContext) FillMessageKeysHolderUsingNewData

func (gc *GroupContext) FillMessageKeysHolderUsingNewData() <-chan crypto.PubKey

func (*GroupContext) FillMessageKeysHolderUsingPreviousData

func (gc *GroupContext) FillMessageKeysHolderUsingPreviousData() <-chan crypto.PubKey

func (*GroupContext) Group

func (gc *GroupContext) Group() *protocoltypes.Group

func (*GroupContext) IsClosed

func (gc *GroupContext) IsClosed() bool

func (*GroupContext) MemberPubKey

func (gc *GroupContext) MemberPubKey() crypto.PubKey

func (*GroupContext) MessageStore

func (gc *GroupContext) MessageStore() *MessageStore

func (*GroupContext) MetadataStore

func (gc *GroupContext) MetadataStore() *MetadataStore

func (*GroupContext) SecretStore added in v1.3.2

func (gc *GroupContext) SecretStore() secretstore.SecretStore

func (*GroupContext) SendSecretsToExistingMembers

func (gc *GroupContext) SendSecretsToExistingMembers(contact crypto.PubKey) <-chan crypto.PubKey

func (*GroupContext) TagGroupContextPeers

func (gc *GroupContext) TagGroupContextPeers(ipfsCoreAPI ipfsutil.ExtendedCoreAPI, weight int)

func (*GroupContext) WatchNewMembersAndSendSecrets

func (gc *GroupContext) WatchNewMembersAndSendSecrets() <-chan crypto.PubKey

type GroupContextMap

type GroupContextMap = sync.Map

type GroupMap

type GroupMap = sync.Map

type GroupOpenMode

type GroupOpenMode uint64
const (
	GroupOpenModeUndefined GroupOpenMode = iota
	GroupOpenModeReplicate
	GroupOpenModeWrite
)

type GroupStatus

type GroupStatus struct {
	// contains filtered or unexported fields
}

type GroupsSigPubKeyMap

type GroupsSigPubKeyMap = sync.Map

type MessageStore

type MessageStore struct {
	basestore.BaseStore
	// contains filtered or unexported fields
}

FIXME: replace cache by a circular buffer to avoid an attack by RAM saturation

func (*MessageStore) AddMessage

func (m *MessageStore) AddMessage(ctx context.Context, payload []byte) (operation.Operation, error)

func (*MessageStore) CacheSizeForDevicePK

func (m *MessageStore) CacheSizeForDevicePK(devicePK []byte) (size int, ok bool)

func (*MessageStore) Close

func (m *MessageStore) Close() error

func (*MessageStore) GetMessageByCID

func (m *MessageStore) GetMessageByCID(c cid.Cid) (operation.Operation, error)

func (*MessageStore) GetOutOfStoreMessageEnvelope

func (m *MessageStore) GetOutOfStoreMessageEnvelope(ctx context.Context, c cid.Cid) (*pushtypes.OutOfStoreMessageEnvelope, error)

func (*MessageStore) ListEvents

func (m *MessageStore) ListEvents(ctx context.Context, since, until []byte, reverse bool) (<-chan *protocoltypes.GroupMessageEvent, error)

FIXME: use iterator instead to reduce resource usage (require go-ipfs-log improvements)

func (*MessageStore) ProcessMessageQueueForDevicePK

func (m *MessageStore) ProcessMessageQueueForDevicePK(ctx context.Context, devicePK []byte)

type MetadataStore

type MetadataStore struct {
	basestore.BaseStore
	// contains filtered or unexported fields
}

func (*MetadataStore) AddDeviceToGroup

func (m *MetadataStore) AddDeviceToGroup(ctx context.Context) (operation.Operation, error)

func (*MetadataStore) ClaimGroupOwnership

func (m *MetadataStore) ClaimGroupOwnership(ctx context.Context, groupSK crypto.PrivKey) (operation.Operation, error)

func (*MetadataStore) Close

func (m *MetadataStore) Close() error

func (*MetadataStore) ContactBlock

func (m *MetadataStore) ContactBlock(ctx context.Context, pk crypto.PubKey) (operation.Operation, error)

ContactBlock indicates the payload includes that the deviceKeystore has blocked a contact

func (*MetadataStore) ContactRequestDisable

func (m *MetadataStore) ContactRequestDisable(ctx context.Context) (operation.Operation, error)

ContactRequestDisable indicates the payload includes that the deviceKeystore has disabled incoming contact requests

func (*MetadataStore) ContactRequestEnable

func (m *MetadataStore) ContactRequestEnable(ctx context.Context) (operation.Operation, error)

ContactRequestEnable indicates the payload includes that the deviceKeystore has enabled incoming contact requests

func (*MetadataStore) ContactRequestIncomingAccept

func (m *MetadataStore) ContactRequestIncomingAccept(ctx context.Context, pk crypto.PubKey) (operation.Operation, error)

ContactRequestIncomingAccept indicates the payload includes that the deviceKeystore has accepted a contact request

func (*MetadataStore) ContactRequestIncomingDiscard

func (m *MetadataStore) ContactRequestIncomingDiscard(ctx context.Context, pk crypto.PubKey) (operation.Operation, error)

ContactRequestIncomingDiscard indicates the payload includes that the deviceKeystore has ignored a contact request

func (*MetadataStore) ContactRequestIncomingReceived

func (m *MetadataStore) ContactRequestIncomingReceived(ctx context.Context, contact *protocoltypes.ShareableContact) (operation.Operation, error)

ContactRequestIncomingReceived indicates the payload includes that the deviceKeystore has received a contact request

func (*MetadataStore) ContactRequestOutgoingEnqueue

func (m *MetadataStore) ContactRequestOutgoingEnqueue(ctx context.Context, contact *protocoltypes.ShareableContact, ownMetadata []byte) (operation.Operation, error)

ContactRequestOutgoingEnqueue indicates the payload includes that the deviceKeystore will attempt to send a new contact request

func (*MetadataStore) ContactRequestOutgoingSent

func (m *MetadataStore) ContactRequestOutgoingSent(ctx context.Context, pk crypto.PubKey) (operation.Operation, error)

ContactRequestOutgoingSent indicates the payload includes that the deviceKeystore has sent a contact request

func (*MetadataStore) ContactRequestReferenceReset

func (m *MetadataStore) ContactRequestReferenceReset(ctx context.Context) (operation.Operation, error)

ContactRequestReferenceReset indicates the payload includes that the deviceKeystore has a new contact request reference

func (*MetadataStore) ContactSendAliasKey

func (m *MetadataStore) ContactSendAliasKey(ctx context.Context) (operation.Operation, error)

func (*MetadataStore) ContactUnblock

func (m *MetadataStore) ContactUnblock(ctx context.Context, pk crypto.PubKey) (operation.Operation, error)

ContactUnblock indicates the payload includes that the deviceKeystore has unblocked a contact

func (*MetadataStore) GetContactFromGroupPK

func (m *MetadataStore) GetContactFromGroupPK(groupPK []byte) *protocoltypes.ShareableContact

func (*MetadataStore) GetDevicesForMember

func (m *MetadataStore) GetDevicesForMember(pk crypto.PubKey) ([]crypto.PubKey, error)

func (*MetadataStore) GetIncomingContactRequestsStatus

func (m *MetadataStore) GetIncomingContactRequestsStatus() (bool, *protocoltypes.ShareableContact)

func (*MetadataStore) GetMemberByDevice

func (m *MetadataStore) GetMemberByDevice(pk crypto.PubKey) (crypto.PubKey, error)

func (*MetadataStore) GetPushTokenForDevice

func (m *MetadataStore) GetPushTokenForDevice(d crypto.PubKey) (*protocoltypes.PushMemberTokenUpdate, error)

func (*MetadataStore) GetRequestOwnMetadataForContact

func (m *MetadataStore) GetRequestOwnMetadataForContact(pk []byte) ([]byte, error)

func (*MetadataStore) GroupJoin

GroupJoin indicates the payload includes that the deviceKeystore has joined a group

func (*MetadataStore) GroupLeave

func (m *MetadataStore) GroupLeave(ctx context.Context, pk crypto.PubKey) (operation.Operation, error)

GroupLeave indicates the payload includes that the deviceKeystore has left a group

func (*MetadataStore) ListAdmins

func (m *MetadataStore) ListAdmins() []crypto.PubKey

func (*MetadataStore) ListContacts

func (m *MetadataStore) ListContacts() map[string]*AccountContact

func (*MetadataStore) ListContactsByStatus

func (m *MetadataStore) ListContactsByStatus(states ...protocoltypes.ContactState) []*protocoltypes.ShareableContact

func (*MetadataStore) ListDevices

func (m *MetadataStore) ListDevices() []crypto.PubKey

func (*MetadataStore) ListEvents

func (m *MetadataStore) ListEvents(ctx context.Context, since, until []byte, reverse bool) (<-chan *protocoltypes.GroupMetadataEvent, error)

FIXME: use iterator instead to reduce resource usage (require go-ipfs-log improvements)

func (*MetadataStore) ListMembers

func (m *MetadataStore) ListMembers() []crypto.PubKey

func (*MetadataStore) ListMultiMemberGroups

func (m *MetadataStore) ListMultiMemberGroups() []*protocoltypes.Group

func (*MetadataStore) ListOtherMembersDevices

func (m *MetadataStore) ListOtherMembersDevices() []crypto.PubKey

func (*MetadataStore) ListVerifiedCredentials

func (m *MetadataStore) ListVerifiedCredentials() []*protocoltypes.AccountVerifiedCredentialRegistered

func (*MetadataStore) RegisterDevicePushServer

func (m *MetadataStore) RegisterDevicePushServer(ctx context.Context, server *protocoltypes.PushServer) (operation.Operation, error)

func (*MetadataStore) RegisterDevicePushToken

func (m *MetadataStore) RegisterDevicePushToken(ctx context.Context, token *protocoltypes.PushServiceReceiver) (operation.Operation, error)

func (*MetadataStore) SendAccountServiceTokenAdded

func (m *MetadataStore) SendAccountServiceTokenAdded(ctx context.Context, token *protocoltypes.ServiceToken) (operation.Operation, error)

func (*MetadataStore) SendAccountServiceTokenRemoved

func (m *MetadataStore) SendAccountServiceTokenRemoved(ctx context.Context, tokenID string) (operation.Operation, error)

func (*MetadataStore) SendAccountVerifiedCredentialAdded

func (m *MetadataStore) SendAccountVerifiedCredentialAdded(ctx context.Context, token *protocoltypes.AccountVerifiedCredentialRegistered) (operation.Operation, error)

func (*MetadataStore) SendAliasProof

func (m *MetadataStore) SendAliasProof(ctx context.Context) (operation.Operation, error)

func (*MetadataStore) SendAppMetadata

func (m *MetadataStore) SendAppMetadata(ctx context.Context, message []byte) (operation.Operation, error)

func (*MetadataStore) SendGroupReplicating

func (m *MetadataStore) SendGroupReplicating(ctx context.Context, t *protocoltypes.ServiceToken, endpoint string) (operation.Operation, error)

func (*MetadataStore) SendPushToken

func (*MetadataStore) SendSecret

func (m *MetadataStore) SendSecret(ctx context.Context, memberPK crypto.PubKey) (operation.Operation, error)

type NewOrbitDBOptions

type NewOrbitDBOptions struct {
	baseorbitdb.NewOrbitDBOptions
	Datastore        datastore.Batching
	SecretStore      secretstore.SecretStore
	RotationInterval *rendezvous.RotationInterval

	GroupMetadataStoreType string
	GroupMessageStoreType  string
	ReplicationMode        bool
}

type Opts

type Opts struct {
	Logger           *zap.Logger
	IpfsCoreAPI      ipfsutil.ExtendedCoreAPI
	DatastoreDir     string
	RootDatastore    ds.Batching
	AccountCache     ds.Batching
	OrbitDB          *WeshOrbitDB
	TinderService    *tinder.Service
	Host             host.Host
	PubSub           *pubsub.PubSub
	GRPCInsecureMode bool
	LocalOnly        bool

	PushKey              *[cryptoutil.KeySize]byte
	SecretStore          secretstore.SecretStore
	OutOfStorePrivateKey *[cryptoutil.KeySize]byte

	// These are used if OrbitDB is nil.
	GroupMetadataStoreType string
	GroupMessageStoreType  string
	// contains filtered or unexported fields
}

Opts contains optional configuration flags for building a new Client

type OrbitDBMessageMarshaler

type OrbitDBMessageMarshaler struct {
	// contains filtered or unexported fields
}

func NewOrbitDBMessageMarshaler

func NewOrbitDBMessageMarshaler(selfid peer.ID, secretStore secretstore.SecretStore, rp *rendezvous.RotationInterval, useReplicationMode bool) *OrbitDBMessageMarshaler

func (*OrbitDBMessageMarshaler) GetDevicePKForPeerID

func (m *OrbitDBMessageMarshaler) GetDevicePKForPeerID(id peer.ID) (pdg *PeerDeviceGroup, ok bool)

func (*OrbitDBMessageMarshaler) Marshal

func (*OrbitDBMessageMarshaler) RegisterGroup

func (m *OrbitDBMessageMarshaler) RegisterGroup(sid string, group *protocoltypes.Group)

func (*OrbitDBMessageMarshaler) RegisterSharedKeyForTopic

func (m *OrbitDBMessageMarshaler) RegisterSharedKeyForTopic(topic string, sk enc.SharedKey)

func (*OrbitDBMessageMarshaler) Unmarshal

func (m *OrbitDBMessageMarshaler) Unmarshal(payload []byte, msg *iface.MessageExchangeHeads) error

type PeerDeviceGroup

type PeerDeviceGroup struct {
	Group    *protocoltypes.Group
	DevicePK crypto.PubKey
}

type PeerStatus

type PeerStatus struct {
	// contains filtered or unexported fields
}

type PeersConnectedness

type PeersConnectedness map[peer.ID]ConnectednessType

type RestoreAccountHandler

type RestoreAccountHandler struct {
	Handler     func(header *tar.Header, reader *tar.Reader) (bool, error)
	PostProcess func() error
}

type Service

type Service interface {
	protocoltypes.ProtocolServiceServer

	Close() error
	Status() Status
	IpfsCoreAPI() ipfs_interface.CoreAPI
}

Service is the main Berty Protocol interface

func NewService added in v1.2.0

func NewService(opts Opts) (_ Service, err error)

NewService initializes a new Service

Example (Basic)
package main

import (
	"context"
	"fmt"

	"berty.tech/weshnet"
	"berty.tech/weshnet/pkg/protocoltypes"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	client, err := weshnet.NewService(weshnet.Opts{})
	if err != nil {
		panic(err)
	}
	defer client.Close()

	ret, err := client.ServiceGetConfiguration(ctx, &protocoltypes.ServiceGetConfiguration_Request{})
	if err != nil {
		panic(err)
	}

	for _, listener := range ret.Listeners {
		if listener == "/p2p-circuit" {
			fmt.Println(listener)
		}
	}

}
Output:

/p2p-circuit

func TestingService

func TestingService(ctx context.Context, t testing.TB, opts Opts) (Service, func())

TestingService returns a configured Client struct with in-memory contexts.

type ServiceClient added in v1.2.0

type ServiceClient interface {
	protocoltypes.ProtocolServiceClient

	io.Closer
}

func NewClientFromService added in v1.2.0

func NewClientFromService(ctx context.Context, s *grpc.Server, svc Service, opts ...grpc.DialOption) (ServiceClient, error)

func NewInMemoryServiceClient added in v1.2.0

func NewInMemoryServiceClient() (ServiceClient, error)

NewInMemoryServiceClient creates a new in-memory Wesh protocol service and returns a gRPC ServiceClient which uses a direct in-memory connection. When finished, you must call Close(). This creates a new Wesh account where the key store is in memory. (If you don't export the data then it is lost when you call Close(). ) The IPFS node, cached data, and configuration are also in memory.

Example (Basic)
package main

import (
	"context"
	"fmt"

	"berty.tech/weshnet"
	"berty.tech/weshnet/pkg/protocoltypes"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	client, err := weshnet.NewInMemoryServiceClient()
	if err != nil {
		panic(err)
	}
	defer client.Close()

	ret, err := client.ServiceGetConfiguration(ctx, &protocoltypes.ServiceGetConfiguration_Request{})
	if err != nil {
		panic(err)
	}

	for _, listener := range ret.Listeners {
		if listener == "/p2p-circuit" {
			fmt.Println(listener)
		}
	}

}
Output:

/p2p-circuit

func NewPersistentServiceClient added in v1.2.0

func NewPersistentServiceClient(path string) (ServiceClient, error)
Example (Basic)
package main

import (
	"context"
	"io/ioutil"
	"os"

	"berty.tech/weshnet"
	"berty.tech/weshnet/pkg/protocoltypes"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	// create a temporary path to host data of our persistant service
	path, err := ioutil.TempDir("", "weshnet-test-persistant")
	if err != nil {
		panic(err)
	}
	defer os.RemoveAll(path)

	var peerid string
	// open once
	{
		client, err := weshnet.NewPersistentServiceClient(path)
		if err != nil {
			panic(err)
		}

		ret, err := client.ServiceGetConfiguration(ctx, &protocoltypes.ServiceGetConfiguration_Request{})
		if err != nil {
			panic(err)
		}

		peerid = ret.PeerID

		if err := client.Close(); err != nil {
			panic(err)
		}
	}

	// open twice
	{
		client, err := weshnet.NewPersistentServiceClient(path)
		if err != nil {
			panic(err)
		}
		defer client.Close()

		ret, err := client.ServiceGetConfiguration(ctx, &protocoltypes.ServiceGetConfiguration_Request{})
		if err != nil {
			panic(err)
		}

		if peerid != ret.PeerID {
			panic("peerid should be identical")
		}
	}

}
Output:

func NewServiceClient added in v1.2.0

func NewServiceClient(opts Opts) (ServiceClient, error)
Example (Basic)
package main

import (
	"context"
	"fmt"

	"berty.tech/weshnet"
	"berty.tech/weshnet/pkg/protocoltypes"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	client, err := weshnet.NewServiceClient(weshnet.Opts{})
	if err != nil {
		panic(err)
	}
	defer client.Close()

	ret, err := client.ServiceGetConfiguration(ctx, &protocoltypes.ServiceGetConfiguration_Request{})
	if err != nil {
		panic(err)
	}

	for _, listener := range ret.Listeners {
		if listener == "/p2p-circuit" {
			fmt.Println(listener)
		}
	}

}
Output:

/p2p-circuit

func TestingClient

func TestingClient(ctx context.Context, t testing.TB, svc Service, clientOpts []grpc.DialOption, serverOpts []grpc.ServerOption) (client ServiceClient, cleanup func())

func TestingClientFromServer

func TestingClientFromServer(ctx context.Context, t testing.TB, s *grpc.Server, svc Service, dialOpts ...grpc.DialOption) (client ServiceClient, cleanup func())

type ServiceMethods

type ServiceMethods interface {
	GetContextGroupForID(id []byte) (*GroupContext, error)
	GetCurrentDevicePushConfig() (*protocoltypes.PushServiceReceiver, *protocoltypes.PushServer)
}

type Status

type Status struct {
	DB       error
	Protocol error
}

Status contains results of status checks

type Swiper

type Swiper struct {
	// contains filtered or unexported fields
}

func NewSwiper

func NewSwiper(logger *zap.Logger, tinder *tinder.Service, rp *rendezvous.RotationInterval) *Swiper

func (*Swiper) Announce

func (s *Swiper) Announce(ctx context.Context, topic, seed []byte)

watch looks for peers providing a resource

func (*Swiper) RefreshContactRequest

func (s *Swiper) RefreshContactRequest(ctx context.Context, topic []byte) (addrs []peer.AddrInfo, err error)

func (*Swiper) WatchTopic

func (s *Swiper) WatchTopic(ctx context.Context, topic, seed []byte) <-chan peer.AddrInfo

WatchTopic looks for peers providing a resource. 'done' is used to alert parent when everything is done, to avoid data races.

type TestingOpts

type TestingOpts struct {
	Logger          *zap.Logger
	Mocknet         libp2p_mocknet.Mocknet
	DiscoveryServer *tinder.MockDriverServer
	SecretStore     secretstore.SecretStore
	CoreAPIMock     ipfsutil.CoreAPIMock
	OrbitDB         *WeshOrbitDB
	ConnectFunc     ConnectTestingProtocolFunc
	PushSK          *[32]byte
}

type TestingProtocol

type TestingProtocol struct {
	Opts *Opts

	Service Service
	Client  ServiceClient

	RootDatastore datastore.Batching
	IpfsCoreAPI   ipfsutil.ExtendedCoreAPI
	OrbitDB       *WeshOrbitDB
	SecretStore   secretstore.SecretStore
}

func NewTestingProtocol

func NewTestingProtocol(ctx context.Context, t testing.TB, opts *TestingOpts, ds datastore.Batching) (*TestingProtocol, func())

func NewTestingProtocolWithMockedPeers

func NewTestingProtocolWithMockedPeers(ctx context.Context, t testing.TB, opts *TestingOpts, ds datastore.Batching, amount int) ([]*TestingProtocol, func())

type WeshOrbitDB added in v1.2.0

type WeshOrbitDB struct {
	baseorbitdb.BaseOrbitDB
	// contains filtered or unexported fields
}

func NewTestOrbitDB

func NewTestOrbitDB(ctx context.Context, t *testing.T, logger *zap.Logger, node ipfsutil.CoreAPIMock, baseDS datastore.Batching) *WeshOrbitDB

func NewWeshOrbitDB added in v1.2.0

func NewWeshOrbitDB(ctx context.Context, ipfs coreapi.CoreAPI, options *NewOrbitDBOptions) (*WeshOrbitDB, error)

func (*WeshOrbitDB) GetDevicePKForPeerID added in v1.2.0

func (s *WeshOrbitDB) GetDevicePKForPeerID(id peer.ID) (pdg *PeerDeviceGroup, ok bool)

func (*WeshOrbitDB) IsGroupLoaded added in v1.2.0

func (s *WeshOrbitDB) IsGroupLoaded(groupID string) bool

func (*WeshOrbitDB) OpenGroup added in v1.2.0

func (*WeshOrbitDB) OpenGroupReplication added in v1.2.0

func (s *WeshOrbitDB) OpenGroupReplication(ctx context.Context, g *protocoltypes.Group, options *orbitdb.CreateDBOptions) (iface.Store, iface.Store, error)

func (*WeshOrbitDB) SetGroupSigPubKey added in v1.2.0

func (s *WeshOrbitDB) SetGroupSigPubKey(groupID string, pubKey crypto.PubKey) error

SetGroupSigPubKey registers a new group signature pubkey, mainly used to replicate a store data without needing to access to its content

Directories

Path Synopsis
internal
handshake
Package handshake implements a capability-based handshake.
Package handshake implements a capability-based handshake.
tools
Package tools ensures that `go mod` detect some required dependencies.
Package tools ensures that `go mod` detect some required dependencies.
pkg
cryptoutil
Package cryptoutil contains generic & stateless crypto helpers.
Package cryptoutil contains generic & stateless crypto helpers.
errcode
Package errcode contains the list of Berty error codes.
Package errcode contains the list of Berty error codes.
grpcutil
Package grpcutil contains gRPC lazy codecs, messages and a buf-based listener.
Package grpcutil contains gRPC lazy codecs, messages and a buf-based listener.
ipfsutil
Package ipfsutil contains helpers around IPFS (logging, datastore, networking, core API, ...).
Package ipfsutil contains helpers around IPFS (logging, datastore, networking, core API, ...).
protocoltypes
This package is generated with Protobuf.
This package is generated with Protobuf.
pushtypes
Package pushtypes is a reverse proxy.
Package pushtypes is a reverse proxy.
replicationtypes
Package replicationtypes is a reverse proxy.
Package replicationtypes is a reverse proxy.
secretstore
Package secretstore contains function related to device, groups and messages keys.
Package secretstore contains function related to device, groups and messages keys.
testutil
Package testutil contains testing helpers (logging, slow skipping).
Package testutil contains testing helpers (logging, slow skipping).
tool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL