File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed
Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 11exports . Client = Client
22exports . Server = Server
33
4- var bignum = require ( 'bignum' )
4+ // optional compiled dependency. if it doesn't compile, no big deal.
5+ var bignum
6+ try {
7+ bignum = require ( 'bignum' )
8+ } catch ( e ) { }
9+
510var bncode = require ( 'bncode' )
611var compact2string = require ( 'compact2string' )
712var dgram = require ( 'dgram' )
@@ -18,6 +23,7 @@ var url = require('url')
1823var CONNECTION_ID = Buffer . concat ( [ toUInt32 ( 0x417 ) , toUInt32 ( 0x27101980 ) ] )
1924var ACTIONS = { CONNECT : 0 , ANNOUNCE : 1 }
2025var EVENTS = { completed : 1 , started : 2 , stopped : 3 }
26+ var MAX_UINT = 4294967295
2127
2228inherits ( Client , EventEmitter )
2329
@@ -522,7 +528,16 @@ function toUInt32 (n) {
522528}
523529
524530function toUInt64 ( n ) {
525- return bignum ( n ) . toBuffer ( { size : 8 } )
531+ if ( typeof bignum === 'function' ) {
532+ return bignum ( n ) . toBuffer ( { size : 8 } )
533+ } else {
534+ // optional compiled dependency 'bignum' is not available, so round down to MAX_UINT.
535+ // These values are only used for tracker stats anyway.
536+ if ( n > MAX_UINT ) {
537+ n = MAX_UINT
538+ }
539+ return Buffer . concat ( [ toUInt32 ( 0 ) , toUInt32 ( n ) ] )
540+ }
526541}
527542
528543function bytewiseEncodeURIComponent ( buf ) {
Original file line number Diff line number Diff line change 1111 "url" : " https://github.com/feross/bittorrent-tracker/issues"
1212 },
1313 "dependencies" : {
14- "bignum" : " ^0.6.2" ,
1514 "bncode" : " ^0.5.2" ,
1615 "compact2string" : " ^1.2.0" ,
1716 "extend.js" : " 0.0.1" ,
2625 "portfinder" : " ^0.2.1" ,
2726 "tape" : " 2.x"
2827 },
28+ "optionalDependencies" : {
29+ "bignum" : " ^0.6.2"
30+ },
2931 "homepage" : " http://webtorrent.io" ,
3032 "keywords" : [
3133 " torrent" ,
You can’t perform that action at this time.
0 commit comments