f2f

package module
v0.0.0-...-d3354c4 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2019 License: LGPL-2.1 Imports: 15 Imported by: 3

README

go-f2f

DEPRECATED

This project is no longer actively developed A p2p stack with a better model is available in the blobcache repo

A friend-to-friend networking library written in Go. f2f takes care of all the boring stuff like finding friendly devices and connecting to them securely.

Quick Start Guide

First make a Host.

h := f2f.NewHost(privateKey, friendList)

privateKey can be from a preexisting key, read in from a file. You can also generate a new using the f2fcrypto package. friendList can be anything that implements friends.Source

Next you "open" a Listener on the host. An f2f.Listener presents a similar interface to net.Listener. All the connections accepted from it will be on the same channel. This enables you to have multiple services in your application communicating over the same secure connection without interfering with one another.

l, err := h.Open(0, "mtls")
for {
  conn, err := l.Accept()
  if err != nil {
    log.Println(err)
    return
  }
  // Do something with `conn` here
}

Mock

In the mock package there is a MockListener which you can use to test services that depend on f2f.Listener

Documentation

Index

Constants

View Source
const MetaChannelID = uint32(0xFFFFFFFF)

Variables

View Source
var (
	ErrIllegalFork  = errors.New("Illegal Fork")
	ErrAddrNotFound = errors.New("Address not found.")
	ErrAddrInvalid  = errors.New("Address is invalid")
)

Functions

This section is empty.

Types

type Addr

type Addr struct {
	Friend friends.ID
	Device DeviceID
}

func (Addr) Equals

func (a Addr) Equals(b *Addr) bool

func (Addr) Key

func (a Addr) Key() string

func (Addr) String

func (a Addr) String() string

func (Addr) Valid

func (a Addr) Valid() bool

type Conn

type Conn interface {
	Read(data []byte) (n int, err error)
	Write(data []byte) (n int, err error)
	Close() error

	LocalAddr() Addr
	RemoteAddr() Addr
}

type DeviceID

type DeviceID [8]byte

func (*DeviceID) String

func (di *DeviceID) String() string

type Host

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

func NewHost

func NewHost(privateKey crypto.Signer, fl friends.Source) (h *Host)

func (*Host) AddDiscovery

func (h *Host) AddDiscovery(provider discovery.Provider)

AddDiscovery starts the given discovery provider.

func (*Host) Addr

func (h *Host) Addr() Addr

func (*Host) Allow

func (h *Host) Allow(who friends.ID) bool

Allow returns true if a host with the given id should be allowed to connect to this host--if "who" is in the friends list or equal to the local id.

func (*Host) Connect

func (h *Host) Connect(who friends.ID, urlstr string) error

func (*Host) LocalAddrs

func (h *Host) LocalAddrs() (addrs []string)

func (*Host) Open

func (h *Host) Open(channelID uint32, transportName string) (n Listener, err error)

func (*Host) SetFriendList

func (h *Host) SetFriendList(fl friends.Source)

SetFriendList will make the host start using the new friend list. It will also update all running discovery providers with the new friend list.

type Listener

type Listener interface {
	Accept() (Conn, error)
	Close() error
	Addr() Addr
}

type TransportService

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

func (*TransportService) Dial

func (ts *TransportService) Dial(raddr string, remoteKey crypto.PublicKey) error

func (*TransportService) RegisterListener

func (ts *TransportService) RegisterListener(l *listener)

func (*TransportService) Run

func (ts *TransportService) Run() error

func (*TransportService) Shutdown

func (ts *TransportService) Shutdown()

Directories

Path Synopsis
examples
ssh

Jump to

Keyboard shortcuts

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