Skip to content

Instantly share code, notes, and snippets.

@gcoakes
Created January 30, 2022 21:50
Show Gist options
  • Save gcoakes/380dbe7d968e298897c737843b965339 to your computer and use it in GitHub Desktop.
Save gcoakes/380dbe7d968e298897c737843b965339 to your computer and use it in GitHub Desktop.
// @ts-check
/** @class Transport */
class Transport {
/**
* @method
* @name dial
* @param {string} multiaddr
* @param {boolean} role_override
* @returns {Promise<Connection>}
* Start attempting to dial the given multiaddress. The returned Promise must
* yield a Connection on success. If the multiaddress is not supported, you
* should return an instance of Error whose name property has been set to the
* string "NotSupportedError".
*/
dial(multiaddr, role_override) {
throw new Error("Not Implemented");
}
/**
* @generator
* @method
* @name listen_on
* @param {string} multiaddr
* @yields {Promise<ListenEvent>}
* Start listening on the given multiaddress. The returned Iterator must yield
* Promises to ListenEvent events. If the multiaddress is not supported, you
* should return an instance of Error whose name property has been set to the
* string "NotSupportedError".
*/
listen_on(multiaddr) {
throw new Error("Not Implemented");
}
}
/** @class Connection */
class Connection {
constructor(multiaddr) {
this._multiaddr = multiaddr;
}
/**
* @generator
* @method
* @name read
* @yields {Promise<ArrayBuffer>} The next chunk of data from the connection.
*/
*read() {
throw new Error("Not Implemented");
}
/**
* @generator
* @method
* @name write
* @param {Uint8Array} data The chunk which should be written to the
* connection.
* @yields {Promise<void>} A promise which resolves when the data is fully
* written to the connection.
*/
*write(data) {
throw new Error("Not Implemented");
}
/**
* @generator
* @method
* @name shutdown
*/
shutdown() {
throw new Error("Not Implemented");
}
/**
* @generator
* @method
* @name close
*/
close() {
throw new Error("Not Implemented");
}
}
/** @class ListenEvent */
class ListenEvent {
/**
* @method
* @name new_addrs
* @returns {string[]} List of addresses we have started listening on. Must be
* an array of strings of multiaddrs.
*/
new_addrs() {
throw new Error("Not Implemented");
}
/**
* @method
* @name expired_addrs
* @returns {string[]} List of addresses that have expired. Must be an array
* of strings of multiaddrs.
*/
expired_addrs() {
throw new Error("Not Implemented");
}
/**
* @method
* @name new_connections
* @returns {ConnectionEvent[]} List of ConnectionEvent object that has been
* received.
*/
new_connections() {
throw new Error("Not Implemented");
}
/**
* @method
* @name next_event
* @returns {Promise<ListenEvent>} Promise to the next event that the listener
* will generate.
*/
next_event() {
throw new Error("Not Implemented");
}
}
/** @class connectionEvent */
class ConnectionEvent {
/**
* @method
* @name connection
* @returns {Connection} The Connection object for communication with the
* remote.
*/
connection() {
throw new Error("Not Implemented");
}
/**
* @method
* @name observed_addr
* @returns {string} The address we observe for the remote connection.
*/
observed_addr() {
throw new Error("Not Implemented");
}
/**
* @method
* @name local_addr
* @returns {string} The address we are listening on, that received the
* remote connection.
*/
local_addr() {
throw new Error("Not Implemented");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment