FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bitcore/Peer.js at master · truevector1/bitcore · GitHub
truevector1
bitcore
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
bitcore
/
Peer.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (51 loc) · 1.63 KB
Breadcrumbs
bitcore
/
Peer.js
Copy path
File metadata and controls
60 lines (51 loc) · 1.63 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require
(
'classtool'
)
;
function
spec
(
b
)
{
var
Net
=
b
.
Net
||
require
(
'net'
)
;
var
Binary
=
b
.
Binary
||
require
(
'binary'
)
;
function
Peer
(
host
,
port
,
services
)
{
if
(
"string"
===
typeof
host
)
{
if
(
host
.
indexOf
(
':'
)
&&
!
port
)
{
var
parts
=
host
.
split
(
':'
)
;
host
=
parts
[
0
]
;
port
=
parts
[
1
]
;
}
this
.
host
=
host
;
this
.
port
=
+
port
||
8333
;
}
else
if
(
host
instanceof
Peer
)
{
this
.
host
=
host
.
host
;
this
.
port
=
host
.
port
;
}
else
if
(
Buffer
.
isBuffer
(
host
)
)
{
if
(
host
.
slice
(
0
,
12
)
.
compare
(
Peer
.
IPV6_IPV4_PADDING
)
!=
0
)
{
throw
new
Error
(
'IPV6 not supported yet! Cannot instantiate host.'
)
;
}
this
.
host
=
Array
.
prototype
.
slice
.
apply
(
host
.
slice
(
12
)
)
.
join
(
'.'
)
;
this
.
port
=
+
port
||
8333
;
}
else
{
throw
new
Error
(
'Could not instantiate peer, invalid parameter type: '
+
typeof
host
)
;
}
this
.
services
=
(
services
)
?
services
:
null
;
this
.
lastSeen
=
0
;
}
;
Peer
.
IPV6_IPV4_PADDING
=
new
Buffer
(
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
255
,
255
]
)
;
Peer
.
prototype
.
createConnection
=
function
(
)
{
var
c
=
Net
.
createConnection
(
this
.
port
,
this
.
host
)
;
return
c
;
}
;
Peer
.
prototype
.
getHostAsBuffer
=
function
(
)
{
return
new
Buffer
(
this
.
host
.
split
(
'.'
)
)
;
}
;
Peer
.
prototype
.
toString
=
function
(
)
{
return
this
.
host
+
":"
+
this
.
port
;
}
;
Peer
.
prototype
.
toBuffer
=
function
(
)
{
var
put
=
Binary
.
put
(
)
;
put
.
word32le
(
this
.
lastSeen
)
;
put
.
word64le
(
this
.
services
)
;
put
.
put
(
this
.
getHostAsBuffer
(
)
)
;
put
.
word16be
(
this
.
port
)
;
return
put
.
buffer
(
)
;
}
;
return
Peer
;
}
;
module
.
defineClass
(
spec
)
;
Back
|
FazBrowse Home
|
New Git URL