Documentation

Overview

    Package tinder is a multi-driver service backed by a cache.

    ┌───────────────────────────────────────────────────┐
    │ Tinder                                            │        ┌───────────────────────┐
    

    ┌───────────────┐ │ │ ┌────▶│ Driver DHT Ipfs │ │ Advertise │▶┼───┐ ┌────────────────┐ │ │ └───────────────────────┘ └───────────────┘ │ │ │ Backoff Cache │ │ │ ┌───────────────────────┐ ┌───────────────┐ │ ├────▶│ Discover │──┐ ┌───────────────┐ │ ├────▶│ Driver DHT Berty │ │ FindPeers │▶┼───┘ └────────────────┘ │ │Driver Manager │ │ │ └───────────────────────┘ └───────────────┘ │ ┌──────────────┴──▶│ (MultiDriver) │─┼──┤ ┌───────────────────────┐ ┌───────────────┐ │ │ └───────────────┘ │ ├────▶│Driver RendezVousPoint │ │ Unregister │▶┼──────────────┘ │ │ └───────────────────────┘ └───────────────┘ │ │ │ ┌───────────────────────┐

    │                                                   │  └────▶│Driver Local (ble/mdns)│
    └───────────────────────────────────────────────────┘        └───────────────────────┘
    

    Index

    Constants

    View Source
    const ScheduleKey = "Schedule"

    Variables

    View Source
    var (
    	ErrInvalidLengthRecords        = fmt.Errorf("proto: negative length found during unmarshaling")
    	ErrIntOverflowRecords          = fmt.Errorf("proto: integer overflow")
    	ErrUnexpectedEndOfGroupRecords = fmt.Errorf("proto: unexpected end of group")
    )

    Functions

    func Schedule

    func Schedule(t time.Time) p2p_discovery.Option

      Schedule advertise at the given time

      Types

      type AsyncMultiDriver

      type AsyncMultiDriver struct{ MultiDriver }

      type AsyncableDriver

      type AsyncableDriver interface {
      	// AsyncableDriver implements Driver to simplify the creation pipeline.
      	// Creator returns AsyncableDriver so that fit both cases.
      	Driver
      
      	AsyncableFindPeers
      }

        AsyncableDriver allows MultiDriver to reuse the same chan for multiple drivers.

        func ComposeAsyncableDriver

        func ComposeAsyncableDriver(driver Driver, find AsyncableFindPeers) AsyncableDriver

        func MonitorDriverAsync

        func MonitorDriverAsync(l *zap.Logger, h p2p_host.Host, adriver AsyncableDriver) (AsyncableDriver, error)

        func NewAsyncMultiDriver

        func NewAsyncMultiDriver(logger *zap.Logger, drivers ...AsyncableDriver) AsyncableDriver

        func NewMockedDriverClient

        func NewMockedDriverClient(host p2p_host.Host, server *MockDriverServer) AsyncableDriver

        func NewRendezvousDiscovery

        func NewRendezvousDiscovery(logger *zap.Logger, host host.Host, rdvPeer peer.ID, rng *mrand.Rand) AsyncableDriver

        type AsyncableFindPeers

        type AsyncableFindPeers interface {
        	// FindPeersAsync works differently than FindPeers.
        	// FindPeersAsync is not expected to close the chan.
        	// Also it's expected to start a goroutine to run the expensive part of the search.
        	// And it's only when the caller have received enough valid peers he shutdown the search canceling the context.
        	FindPeersAsync(context.Context, chan<- peer.AddrInfo, string, ...discovery.Option) error
        }

        type DHTDriver

        type DHTDriver struct {
        	p2p_discovery.Discovery
        	Unregisterer
        }

        func (*DHTDriver) Name

        func (d *DHTDriver) Name() string

        type Driver

        type Driver interface {
        	p2p_discovery.Discovery
        	Unregisterer
        
        	Name() string
        }

          Driver is a Discovery with a unregister method

          func ComposeDriver

          func ComposeDriver(name string, advertiser p2p_discovery.Advertiser, discover p2p_discovery.Discoverer, unregister Unregisterer) Driver

          func MonitorDriver

          func MonitorDriver(l *zap.Logger, h p2p_host.Host, driver Driver) (Driver, error)

          func NewDHTDriver

          func NewDHTDriver(d *dht.IpfsDHT) Driver

          func NewLocalDiscovery

          func NewLocalDiscovery(logger *zap.Logger, host host.Host, rng *mrand.Rand) Driver

          func NewMultiDriver

          func NewMultiDriver(logger *zap.Logger, drivers ...Driver) Driver

          type DriverMonitor

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

          func (*DriverMonitor) Advertise

          func (d *DriverMonitor) Advertise(ctx context.Context, ns string, opts ...p2p_discovery.Option) (ttl time.Duration, err error)

          func (*DriverMonitor) Emit

          func (d *DriverMonitor) Emit(evt *EvtDriverMonitor)

          func (*DriverMonitor) FindPeers

          func (d *DriverMonitor) FindPeers(ctx context.Context, ns string, opts ...p2p_discovery.Option) (<-chan p2p_peer.AddrInfo, error)

          func (*DriverMonitor) FindPeersAsync

          func (d *DriverMonitor) FindPeersAsync(ctx context.Context, ccMonitor chan<- p2p_peer.AddrInfo, ns string, opts ...p2p_discovery.Option) error

          func (*DriverMonitor) Name

          func (d *DriverMonitor) Name() string

          func (*DriverMonitor) Unregister

          func (d *DriverMonitor) Unregister(ctx context.Context, ns string) error

          type DriverRouting

          type DriverRouting interface {
          	p2p_routing.Routing
          
          	Driver
          }

          func NewDriverRouting

          func NewDriverRouting(logger *zap.Logger, name string, r p2p_routing.Routing) DriverRouting

          type EventMonitor

          type EventMonitor int
          const (
          	TypeEventMonitorUnknown EventMonitor = iota
          	TypeEventMonitorAdvertise
          	TypeEventMonitorFoundPeer
          )

          type EvtDriverMonitor

          type EvtDriverMonitor struct {
          	EventType  EventMonitor
          	Topic      string
          	AddrInfo   p2p_peer.AddrInfo
          	DriverName string
          }

          type MockDriverServer

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

          func NewMockedDriverServer

          func NewMockedDriverServer() *MockDriverServer

          func (*MockDriverServer) Advertise

          func (s *MockDriverServer) Advertise(ns string, info p2p_peer.AddrInfo, ttl time.Duration) (time.Duration, error)

          func (*MockDriverServer) FindPeers

          func (s *MockDriverServer) FindPeers(ns string, limit int) (<-chan p2p_peer.AddrInfo, error)

          func (*MockDriverServer) FindPeersAsync

          func (s *MockDriverServer) FindPeersAsync(ctx context.Context, outChan chan<- p2p_peer.AddrInfo, ns string, limit int)

          func (*MockDriverServer) HasPeerRecord

          func (s *MockDriverServer) HasPeerRecord(ns string, pid p2p_peer.ID) bool

          func (*MockDriverServer) Reset

          func (s *MockDriverServer) Reset()

          func (*MockDriverServer) Unregister

          func (s *MockDriverServer) Unregister(ns string, pid p2p_peer.ID)

          type MultiDriver

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

            MultiDriver is a simple driver manager, that forward request across multiple driver

            func (*MultiDriver) Advertise

            func (md *MultiDriver) Advertise(ctx context.Context, ns string, opts ...p2p_discovery.Option) (time.Duration, error)

              Advertise simply dispatch Advertise request across all the drivers

              func (*MultiDriver) FindPeers

              func (md *MultiDriver) FindPeers(ctx context.Context, ns string, opts ...p2p_discovery.Option) (<-chan p2p_peer.AddrInfo, error)

              func (*MultiDriver) FindPeersAsync

              func (md *MultiDriver) FindPeersAsync(ctx context.Context, outPeers chan<- p2p_peer.AddrInfo, ns string, opts ...p2p_discovery.Option) error

                FindPeersAsync expect the caller to use it asynchronously and cancel the context with enough peers or found (or deadline exceeded). If the context is not canceled the search will go indefinitely.

                func (*MultiDriver) Name

                func (*MultiDriver) Name() string

                func (*MultiDriver) Unregister

                func (md *MultiDriver) Unregister(ctx context.Context, ns string) error

                type Record

                type Record struct {
                	Cid                  string   `protobuf:"bytes,1,opt,name=cid,proto3" json:"cid,omitempty"`
                	Expire               int64    `protobuf:"varint,2,opt,name=expire,proto3" json:"expire,omitempty"`
                	XXX_NoUnkeyedLiteral struct{} `json:"-"`
                	XXX_unrecognized     []byte   `json:"-"`
                	XXX_sizecache        int32    `json:"-"`
                }

                func (*Record) Descriptor

                func (*Record) Descriptor() ([]byte, []int)

                func (*Record) GetCid

                func (m *Record) GetCid() string

                func (*Record) GetExpire

                func (m *Record) GetExpire() int64

                func (*Record) Marshal

                func (m *Record) Marshal() (dAtA []byte, err error)

                func (*Record) MarshalTo

                func (m *Record) MarshalTo(dAtA []byte) (int, error)

                func (*Record) MarshalToSizedBuffer

                func (m *Record) MarshalToSizedBuffer(dAtA []byte) (int, error)

                func (*Record) ProtoMessage

                func (*Record) ProtoMessage()

                func (*Record) Reset

                func (m *Record) Reset()

                func (*Record) Size

                func (m *Record) Size() (n int)

                func (*Record) String

                func (m *Record) String() string

                func (*Record) Unmarshal

                func (m *Record) Unmarshal(dAtA []byte) error

                func (*Record) XXX_DiscardUnknown

                func (m *Record) XXX_DiscardUnknown()

                func (*Record) XXX_Marshal

                func (m *Record) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

                func (*Record) XXX_Merge

                func (m *Record) XXX_Merge(src proto.Message)

                func (*Record) XXX_Size

                func (m *Record) XXX_Size() int

                func (*Record) XXX_Unmarshal

                func (m *Record) XXX_Unmarshal(b []byte) error

                type Records

                type Records struct {
                	Records              []*Record `protobuf:"bytes,1,rep,name=records,proto3" json:"records,omitempty"`
                	XXX_NoUnkeyedLiteral struct{}  `json:"-"`
                	XXX_unrecognized     []byte    `json:"-"`
                	XXX_sizecache        int32     `json:"-"`
                }

                func (*Records) Descriptor

                func (*Records) Descriptor() ([]byte, []int)

                func (*Records) GetRecords

                func (m *Records) GetRecords() []*Record

                func (*Records) Marshal

                func (m *Records) Marshal() (dAtA []byte, err error)

                func (*Records) MarshalTo

                func (m *Records) MarshalTo(dAtA []byte) (int, error)

                func (*Records) MarshalToSizedBuffer

                func (m *Records) MarshalToSizedBuffer(dAtA []byte) (int, error)

                func (*Records) ProtoMessage

                func (*Records) ProtoMessage()

                func (*Records) Reset

                func (m *Records) Reset()

                func (*Records) Size

                func (m *Records) Size() (n int)

                func (*Records) String

                func (m *Records) String() string

                func (*Records) Unmarshal

                func (m *Records) Unmarshal(dAtA []byte) error

                func (*Records) XXX_DiscardUnknown

                func (m *Records) XXX_DiscardUnknown()

                func (*Records) XXX_Marshal

                func (m *Records) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

                func (*Records) XXX_Merge

                func (m *Records) XXX_Merge(src proto.Message)

                func (*Records) XXX_Size

                func (m *Records) XXX_Size() int

                func (*Records) XXX_Unmarshal

                func (m *Records) XXX_Unmarshal(b []byte) error

                type Service

                type Service interface {
                	Driver
                }

                  Tinder service is a simple driver backed by a cache,

                  func NewService

                  func NewService(logger *zap.Logger, driver Driver, stratFactory p2p_discovery.BackoffFactory, opts ...p2p_discovery.BackoffDiscoveryOption) (Service, error)

                  type StreamWrapper

                  type StreamWrapper struct {
                  	network.Stream
                  	io.ReadWriter
                  }

                  func (*StreamWrapper) Read

                  func (s *StreamWrapper) Read(b []byte) (int, error)

                    Implementation of the io.ReadWriter interface

                    func (*StreamWrapper) Write

                    func (s *StreamWrapper) Write(b []byte) (int, error)

                      Implementation of the io.ReadWriter interface

                      type Unregisterer

                      type Unregisterer interface {
                      	Unregister(ctx context.Context, ns string) error
                      }
                      var NoopUnregisterer Unregisterer = &noopUnregisterer{}