Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const STATUS = {
- OPEN: 0,
- CLOSED: 1,
- CLOSING: 2,
- }
- const ROLE = {
- INITIATOR: 0,
- RESPONDER: 1
- }
- class Connection {
- constructor (peerInfo, remoteMa, isInitiator) {
- /**
- * Connection identifier
- */
- this.id = (~~(Math.random() * 1e9)).toString(36) + Date.now()
- /**
- * Remote peer info
- */
- this.peerInfo = peerInfo
- /**
- * Status of the connection
- */
- this.status = STATUS.OPEN
- /**
- * Endpoints multiaddrs
- */
- this.endpoints = {
- local: undefined,
- remote: remoteMa
- }
- /**
- * Connection timeline
- */
- this.timeline = {
- openTs: Date.now(),
- closeTs: undefined
- }
- /**
- * Role in the connection, initiator or responder
- */
- this.role = isInitiator ? ROLE.INITIATOR : ROLE.RESPONDER
- /**
- * The multiplexer being used
- */
- this.multiplexer = undefined
- /**
- * The encryption method being used
- */
- this.encryption = undefined
- /**
- * Connection streams
- */
- this.streams = []
- /**
- * User provided tags
- */
- this.tags = []
- }
- newStream () {
- if (!this.multiplexer) {
- // await hasMultiplexerOrErrored() // magic ensues
- }
- // ... new stream creation
- }
- getStreams () {
- }
- close () {
- this.timeline.closeTs = Date.now()
- }
- setLocalAddress (ma) {
- this.endpoints.local = ma
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement