Documentation
¶
Overview ¶
Package p2pmobile is a small facade over p2pnet and pairclient for gomobile bind. It exports only types gomobile supports: strings, bools, error, interfaces and pointers to structs.
It imports only p2pnet, p2ppair and pairclient, never libp2p directly, so the import boundary of p2pnet holds for the Android library too.
Index ¶
Constants ¶
const ( CodeInvalidLink = "invalid_link" CodeExpired = "expired" CodeOpenRelay = "open_relay" CodeGone = "gone" CodeTooManyTries = "too_many_tries" CodeWrongServer = "wrong_server" CodeNeedsRelay = "needs_relay" CodeNoRoute = "no_route" CodeUnreachable = "unreachable" CodeFailed = "failed" )
Error codes of PairJSON. They are stable: the app chooses its own words for each one.
Variables ¶
This section is empty.
Functions ¶
func Pair ¶
Pair redeems an invite link and returns the result as JSON. The identity file is created when it does not exist. The caller stores the result. PairJSON gives the same result with a stable error code.
func PairJSON ¶
PairJSON redeems an invite link like Pair and never fails. It answers {"ok":true,"result":{...}} with the object of Pair, or {"ok":false,"code":"...","detail":"..."} where code is one of the Code constants and detail is the error text, for logs.
func Version ¶
func Version() string
Version names the library and its API revision. The app calls it first to prove that the native library loaded; bump the number when the exported API changes.
p2pmobile/3 adds the routes state line of StartForward; the exports and their arguments are those of p2pmobile/2, so a caller of p2pmobile/2 works unchanged if it ignores state lines it does not know.
p2pmobile/4 adds device_credential, sign_in and owner_name to the result of Pair and PairJSON for a sign-in invite; the exports are unchanged.
Types ¶
type Forwarder ¶
type Forwarder struct {
// contains filtered or unexported fields
}
Forwarder forwards a local loopback port to a peer.
func StartForward ¶
func StartForward(identityPath, peerID, listenAddr, relays, addrs, hints string, cb StateCallback) (*Forwarder, error)
StartForward listens on listenAddr and forwards each connection to the peer. relays, addrs and hints are JSON arrays of multiaddrs, or empty. hints are the public relays of the invite (key h): they only help a hole punch and never carry data.
cb gets the state lines: ready, up, down and closed, and a routes line {"state":"routes","addrs":[...],"relays":[...],"hints":[...]} after each connection that opens and every 10 minutes while the forward stays up. The routes line has the current routes of the server; the caller stores them and passes them to the next StartForward.
type StateCallback ¶
type StateCallback interface {
OnState(json string)
}
StateCallback receives one JSON object per state change of a forward.