Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
fix: remove uuid dependency (#68)
Browse files Browse the repository at this point in the history
Removes the dependency on uuid. Use a simpler random string generator instead.
  • Loading branch information
ckousik committed Jan 3, 2023
1 parent 4547406 commit fb14b88
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,13 @@
"multihashes": "^4.0.3",
"p-defer": "^4.0.0",
"uint8arraylist": "^2.3.3",
"uint8arrays": "^4.0.2",
"uuid": "^9.0.0"
"uint8arrays": "^4.0.2"
},
"devDependencies": {
"@libp2p/interface-mocks": "^8.0.1",
"@libp2p/peer-id-factory": "^1.0.19",
"@protobuf-ts/plugin": "^2.8.0",
"@protobuf-ts/protoc": "^2.8.0",
"@types/uuid": "^8.3.4",
"aegir": "^37.6.6",
"it-first": "^2.0.0",
"libp2p": "^0.40.0"
Expand Down
5 changes: 2 additions & 3 deletions src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import * as p from '@libp2p/peer-id'
import type { Multiaddr } from '@multiformats/multiaddr'
import * as multihashes from 'multihashes'
import defer from 'p-defer'
import { v4 as genUuid } from 'uuid'
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
import { concat } from 'uint8arrays/concat'

import { dataChannelError, inappropriateMultiaddr, unimplemented, invalidArgument } from './error.js'
import { WebRTCMultiaddrConnection } from './maconn.js'
import { DataChannelMuxerFactory } from './muxer.js'
import type { WebRTCDialOptions } from './options.js'
import * as sdp from './sdp.js'
import { WebRTCStream } from './stream.js'
import { genUfrag } from './util.js'

const log = logger('libp2p:webrtc:transport')

Expand Down Expand Up @@ -142,7 +141,7 @@ export class WebRTCTransport implements Transport {
dataChannelOpenPromise.reject(dataChannelError('data', error))
}

const ufrag = 'libp2p+webrtc+v1/' + genUuid().replaceAll('-', '')
const ufrag = 'libp2p+webrtc+v1/' + genUfrag(32)

// Create offer and munge sdp with ufrag = pwd. This allows the remote to
// respond to STUN messages without performing an actual SDP exchange.
Expand Down
3 changes: 3 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ export const nopSource = {
}

export const nopSink = async (_: any) => {}

const charset = Array.from('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/')
export const genUfrag = (len: number): string => [...Array(len)].map(() => charset.at(Math.floor(Math.random() * charset.length))).join('')

0 comments on commit fb14b88

Please sign in to comment.