MCPcopy Create free account
hub / github.com/ambianic/peerfetch / PeerFetch

Class PeerFetch

javascript/src/peerfetch.ts:18–648  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16 *
17*/
18export class PeerFetch {
19
20 /**
21 * A PeerJS instance that provides lower layer p2p connectivity API
22 */
23 private _peer?: Peer
24
25 /**
26 * Configuration parameters for the p2p network connection.
27 */
28 private _config: Peer.PeerJSOption
29
30 /**
31 * An identifier of this PeerJS instance that is unique within the p2p network that it participates.
32 * It is assigned by the signaling server. Similar to an http session ID.
33 */
34 private _myPeerId?: string
35
36 /**
37 * Peer ID of the remote node that will proxy http requests
38 */
39 private _remotePeerID?: string
40
41 /**
42 * Tracks current status of the connection to the signaling server
43 */
44 private _signalingConnectionStatus: ConnectionStatus = ConnectionStatus.DISCONNECTED
45
46 /**
47 * Tracks current status of the connection to the remote peer
48 */
49 private _peerConnectionStatus: ConnectionStatus = ConnectionStatus.DISCONNECTED
50
51 /**
52 * The current peer data connection that http requests ride on.
53 * Currently a single peer data connection is managed per PeerFetch instance.
54 */
55 private _dataConnection?: Peer.DataConnection
56
57 /**
58 * Map of pending HTTP requests
59 */
60 private _requestMap: Map<number, any> = new Map()
61
62 /**
63 * Refernce to a timer that runs keepalive pings to the remote peer.
64 */
65 private _keepAlive?: ReturnType<typeof setTimeout>
66
67 /**
68 * Ticketing enforces a strict order or processing for pending http requests and corresponding responses.
69 * Each async request from client code draws a new ticket.
70 * Tickets are processed in the sequential monotonic order that they are drawn.
71 * Once a request is fully processed, its ticket is burned and the next ticket is processed.
72 * A request ticket is not fully processed until the corresponding final HTTP response is received.
73 *
74 * /
75

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected