ipfs

package module
v0.0.0-...-984a975 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: Apache-2.0 Imports: 37 Imported by: 0

README

Concepts

Discovery

  • DHT/kadelmia. Avoid 'dual' - it gets confused. LAN/local should be kept separated, use auth.
  • mDNS local
  • also called 'signaling' in WebRTC
  • key is a SHA32 (of something), value is the address[]
  • example key: sha("/libp2p/relay") - address are nodes providing relay service

Circuits / Relay

  • IPFS network provides a number of well-known and discoverable open relays
  • useful for 'behind the NAT' - but should be used primarily for signaling
  • IMO the use or relay for data is a major flaw in IPFS/LIBP2P.

A better alternative is to use them only for push, with a larger set of nodes ( ideally all ), to initiate quic or webrtc connections. For fallback - standard TURN servers could be used.

This allows many home servers to get high speed ( no relay ).

Record store

  • Key is a public key - ideally ED25519
  • Value is a signed proto, typically a /ipfs address but it's a byte[]

Transports

Unfortunately IPFS has major NIH problems around transports. While the concepts are great and similar to modern standards (H2, H3), they made a choice to reject standards under the claim of 'decentralization'.

For example mTLS arbitrarily invents an new extension to pass public key, which makes absolutely no sense. Instead of 'decentralized' all protocols are locked in to IPFS.

However it is possible to plug in different transports, and to use standard based ones instead. For communication with the current IPFS infra - mainly DHT and circuit - we need to support at least TCP and their incompatible QUIC.

For browsers - there is relatively little value in having browsers act as full DHT nodes. Browsers with WSS require servers with real certs - in which case it is better to use standard protocols to the server, and have the server handle IPFS.

webrtc

  • compatible with browsers, not well maintained (3/21 - doesn't compile)
  • 'star' and 'direct'
  • /dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star/p2p/
  • star not supported in go, protocol not documented/clear
  • incomplete, security not based on webrtc certs.

ws + mplex + noise|secio

  • primarily for use with browser-based nodes, without RTC
  • requires DNS certs (apparently for wss)

quic

  • not compatible with browsers
  • flow control on streams
  • mostly standards based
  • using modified TLS - so not interoperable with non-libp2p clients

Interfaces

API

https://docs.ipfs.io/reference/http/api/

http://localhost:5001/api/v0/swarm/peers query: arg (repeated), rest are flags.

Response: JSON

Gateway

/p2p/${PEER_ID}/http/${PATH}

/p2p/${PEER_ID}/x/${PROTO}/http/${PATH}

Documentation

Index

Constants

View Source
const Protocol = "/ugate/0.0.1"

Variables

This section is empty.

Functions

func P2PAddrFromString

func P2PAddrFromString(c string) (*peer.AddrInfo, error)

Types

type IPFS

type IPFS struct {
	*IPFSConfig

	Host host.Host

	// Only set for discovery nodes.
	// Mobile/battery powered/clients use Routing
	DHT *dht.IpfsDHT

	// Combines ContentRouting, PeerRouting, ValueStore
	Routing routing.Routing // may be same as DHT
	// contains filtered or unexported fields
}

ConnectionGater, Server

func InitIPFS

func InitIPFS(auth *auth.Auth, p2pport int, mux *http.ServeMux) *IPFS

InitIPFS creates LibP2P compatible transport. Identity is based on the EC256 workload identity in auth.

Will use a select set of transports, remotely based on standards: - QUIC - WS

UGate implements H2, WebRTC variants, with a IPFS transport adapter.

func (*IPFS) Find

func (p2p *IPFS) Find(ns string)

func (*IPFS) InitEvent

func (p2p *IPFS) InitEvent()

Track events in the P2P implementation

func (*IPFS) InterceptAccept

func (p2p *IPFS) InterceptAccept(multiaddrs network.ConnMultiaddrs) (allow bool)

func (*IPFS) InterceptAddrDial

func (p2p *IPFS) InterceptAddrDial(id peer.ID, m multiaddr.Multiaddr) (allow bool)

func (*IPFS) InterceptPeerDial

func (p2p *IPFS) InterceptPeerDial(p peer.ID) (allow bool)

func (*IPFS) InterceptSecured

func (p2p *IPFS) InterceptSecured(direction network.Direction, id peer.ID, multiaddrs network.ConnMultiaddrs) (allow bool)

func (*IPFS) InterceptUpgraded

func (p2p *IPFS) InterceptUpgraded(conn network.Conn) (allow bool, reason control.DisconnectReason)

func (*IPFS) Provide

func (p2p *IPFS) Provide(ns string) error

Announce this node is a provider for the key. Normally used for IPFS, key is the sha of the content. Also used for advertise, in Discovery and autorelay.go (/libp2p/relay) According to routing.go, 24h is the normal validity, recommended 6hours refresh.

func (*IPFS) Put

func (p2p *IPFS) Put(key ed25519.PrivateKey, v []byte, seq uint64, exp time.Duration) (string, error)

StartListener a signed proto, key is the public key. 'IPNS' - typically the value is an ipfs address, but can be anything.

func (*IPFS) ServeHTTP

func (p2p *IPFS) ServeHTTP(w http.ResponseWriter, r *http.Request)

IPFS debug/control function

type IPFSConfig

type IPFSConfig struct {
	// If true enable the DHT functionality.
	// In this mode, we act as 'control plane'. If false, the node acts
	// as a gateway, using a CP for discovery and control.
	// The DHT requires maintaining a lot of connections, best for an internet
	// connected host - not for mobile.
	UseDHT bool
}

type PeeringService

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

PeeringService maintains connections to specified peers, reconnecting on disconnect with a back-off.

func NewPeeringService

func NewPeeringService(host host.Host) *PeeringService

NewPeeringService constructs a new peering service. Peers can be added and removed immediately, but connections won't be formed until `Start` is called.

func (*PeeringService) AddPeer

func (ps *PeeringService) AddPeer(info peer.AddrInfo)

AddPeer adds a peer to the peering service. This function may be safely called at any time: before the service is started, while running, or after it stops.

StartListener peer may also be called multiple times for the same peer. The new addresses will replace the old.

func (*PeeringService) RemovePeer

func (ps *PeeringService) RemovePeer(id peer.ID)

RemovePeer removes a peer from the peering service. This function may be safely called at any time: before the service is started, while running, or after it stops.

func (*PeeringService) Start

func (ps *PeeringService) Start() error

Start starts the peering service, connecting and maintaining connections to all registered peers. It returns an error if the service has already been stopped.

func (*PeeringService) Stop

func (ps *PeeringService) Stop() error

Stop stops the peering service.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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