Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
0f19cbc6
Commit
0f19cbc6
authored
Nov 09, 2016
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p/discv5: fix build with Go 1.5, delete package testimg
parent
49da4298
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
879 deletions
+18
-879
1
p2p/discv5/testimg/1
+0
-173
2
p2p/discv5/testimg/2
+0
-178
testimg.1
p2p/discv5/testimg/testimg.1
+0
-191
testimg.go
p2p/discv5/testimg/testimg.go
+0
-335
ticket.go
p2p/discv5/ticket.go
+18
-2
No files found.
p2p/discv5/testimg/1
deleted
100644 → 0
View file @
49da4298
package
main
import
(
"bufio"
"encoding/binary"
"fmt"
"image"
"image/png"
"os"
"sort"
"strconv"
"github.com/ethereum/go-ethereum/crypto"
)
var
xs
,
ys
,
maxTime
int
func
set
(
pic
*
image
.
NRGBA
,
x
,
y
,
c
,
v
int
)
{
if
v
>
255
{
v
=
255
}
if
x
>=
0
&&
x
<
xs
&&
y
>=
0
&&
y
<
ys
{
pic
.
Pix
[
y
*
pic
.
Stride
+
x
*
4
+
c
]
=
uint8
(
v
)
}
}
func
main
()
{
topicHash
:=
crypto
.
Keccak256Hash
([]
byte
(
"foo"
))
fmt
.
Println
(
topicHash
)
topicPrefix
:=
binary
.
BigEndian
.
Uint64
(
topicHash
[:
8
])
var
nodes
uint64Slice
inputFile
:=
"test.out"
if
len
(
os
.
Args
)
>
1
{
inputFile
=
os
.
Args
[
1
]
}
f
,
_
:=
os
.
Open
(
inputFile
)
scanner
:=
bufio
.
NewScanner
(
f
)
scanner
.
Split
(
bufio
.
ScanWords
)
for
scanner
.
Scan
()
{
w
:=
scanner
.
Text
()
if
w
==
"*N"
{
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
nodes
=
append
(
nodes
,
prefix
^
topicPrefix
)
}
if
w
==
"*R"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
if
int
(
time
)
>
maxTime
{
maxTime
=
int
(
time
)
}
}
}
f
.
Close
()
sort
.
Sort
(
nodes
)
nodeIdx
:=
make
(
map
[
uint64
]
int
)
for
i
,
v
:=
range
nodes
{
nodeIdx
[
v
^
topicPrefix
]
=
i
}
xs
=
maxTime
/
10000
ys
=
len
(
nodes
)
pic
:=
image
.
NewNRGBA
(
image
.
Rect
(
0
,
0
,
xs
,
ys
))
for
y
:=
0
;
y
<
ys
;
y
++
{
for
x
:=
0
;
x
<
xs
;
x
++
{
set
(
pic
,
x
,
y
,
3
,
255
)
}
}
pic2
:=
image
.
NewNRGBA
(
image
.
Rect
(
0
,
0
,
xs
,
ys
))
for
y
:=
0
;
y
<
ys
;
y
++
{
for
x
:=
0
;
x
<
xs
;
x
++
{
set
(
pic2
,
x
,
y
,
3
,
255
)
}
}
f
,
_
=
os
.
Open
(
inputFile
)
scanner
=
bufio
.
NewScanner
(
f
)
scanner
.
Split
(
bufio
.
ScanWords
)
nodeRad
:=
make
(
map
[
uint64
]
int
)
for
scanner
.
Scan
()
{
w
:=
scanner
.
Text
()
if
w
==
"*R"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
scanner
.
Scan
()
rad
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
if
int
(
rad
)
!= nodeRad[prefix] {
nodeRad
[
prefix
]
=
int
(
rad
)
radUint
:=
uint64
(
rad
)
*
((^
uint64
(
0
))
/
1000000
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
y
:=
sort
.
Search
(
ys
,
func
(
i
int
)
bool
{
return
nodes
[
i
]
>
radUint
})
set
(
pic
,
x
,
y
,
1
,
255
)
}
}
if
w
==
"*MR"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
scanner
.
Scan
()
scanner
.
Scan
()
rad
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
radUint
:=
uint64
(
rad
)
*
((^
uint64
(
0
))
/
1000000
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
y
:=
sort
.
Search
(
ys
,
func
(
i
int
)
bool
{
return
nodes
[
i
]
>
radUint
})
set
(
pic
,
x
,
y
,
0
,
255
)
}
if
w
==
"*W"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
scanner
.
Scan
()
wp
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
y
:=
nodeIdx
[
prefix
]
set
(
pic2
,
x
,
y
,
0
,
int
(
wp
/
100000
))
set
(
pic2
,
x
,
y
,
1
,
int
(
wp
/
10000
))
set
(
pic2
,
x
,
y
,
2
,
int
(
wp
/
1000
))
}
if
w
==
"*+"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
y
:=
nodeIdx
[
prefix
]
set
(
pic
,
x
,
y
,
2
,
255
)
scanner
.
Scan
()
}
}
f
.
Close
()
f
,
_
=
os
.
Create
(
"test.png"
)
w
:=
bufio
.
NewWriter
(
f
)
png
.
Encode
(
w
,
pic
)
w
.
Flush
()
f
.
Close
()
f
,
_
=
os
.
Create
(
"test2.png"
)
w
=
bufio
.
NewWriter
(
f
)
png
.
Encode
(
w
,
pic2
)
w
.
Flush
()
f
.
Close
()
}
type
uint64Slice
[]
uint64
//
Len
is
the
number
of
elements
in
the
collection
.
func
(
s
uint64Slice
)
Len
()
int
{
return
len
(
s
)
}
//
Less
reports
whether
the
element
with
//
index
i
should
sort
before
the
element
with
index
j
.
func
(
s
uint64Slice
)
Less
(
i
,
j
int
)
bool
{
return
s
[
i
]
<
s
[
j
]
}
//
Swap
swaps
the
elements
with
indexes
i
and
j
.
func
(
s
uint64Slice
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
p2p/discv5/testimg/2
deleted
100644 → 0
View file @
49da4298
package
main
import
(
"bufio"
"encoding/binary"
"fmt"
"image"
"image/png"
"os"
"sort"
"strconv"
"github.com/ethereum/go-ethereum/crypto"
)
var
xs
,
ys
,
maxTime
int
func
set
(
pic
*
image
.
NRGBA
,
x
,
y
,
c
,
v
int
)
{
if
v
>
255
{
v
=
255
}
if
x
>=
0
&&
x
<
xs
&&
y
>=
0
&&
y
<
ys
{
pic
.
Pix
[
y
*
pic
.
Stride
+
x
*
4
+
c
]
=
uint8
(
v
)
}
}
func
main
()
{
topics
:=
make
(
map
[
string
]
uint64
)
var
nodes
uint64Slice
inputFile
:=
"test.out"
if
len
(
os
.
Args
)
>
1
{
inputFile
=
os
.
Args
[
1
]
}
f
,
_
:=
os
.
Open
(
inputFile
)
scanner
:=
bufio
.
NewScanner
(
f
)
scanner
.
Split
(
bufio
.
ScanWords
)
for
scanner
.
Scan
()
{
w
:=
scanner
.
Text
()
if
w
==
"*N"
{
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
nodes
=
append
(
nodes
,
prefix
^
topicPrefix
)
}
if
w
==
"*R"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
if
int
(
time
)
>
maxTime
{
maxTime
=
int
(
time
)
}
scanner
.
Scan
()
topic
:=
scanner
.
Text
()
if
_
,
ok
:=
topics
[
topic
];
!ok {
fmt
.
Println
(
topic
)
topicHash
:=
crypto
.
Keccak256Hash
([]
byte
(
topic
))
topics
[
topic
]
:=
binary
.
BigEndian
.
Uint64
(
topicHash
[:
8
])
}
}
}
f
.
Close
()
sort
.
Sort
(
nodes
)
nodeIdx
:=
make
(
map
[
uint64
]
int
)
for
i
,
v
:=
range
nodes
{
nodeIdx
[
v
^
topicPrefix
]
=
i
}
xs
=
maxTime
/
10000
ys
=
len
(
nodes
)
pic
:=
image
.
NewNRGBA
(
image
.
Rect
(
0
,
0
,
xs
,
ys
))
for
y
:=
0
;
y
<
ys
;
y
++
{
for
x
:=
0
;
x
<
xs
;
x
++
{
set
(
pic
,
x
,
y
,
3
,
255
)
}
}
pic2
:=
image
.
NewNRGBA
(
image
.
Rect
(
0
,
0
,
xs
,
ys
))
for
y
:=
0
;
y
<
ys
;
y
++
{
for
x
:=
0
;
x
<
xs
;
x
++
{
set
(
pic2
,
x
,
y
,
3
,
255
)
}
}
f
,
_
=
os
.
Open
(
inputFile
)
scanner
=
bufio
.
NewScanner
(
f
)
scanner
.
Split
(
bufio
.
ScanWords
)
nodeRad
:=
make
(
map
[
uint64
]
int
)
for
scanner
.
Scan
()
{
w
:=
scanner
.
Text
()
if
w
==
"*R"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
scanner
.
Scan
()
rad
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
if
int
(
rad
)
!= nodeRad[prefix] {
nodeRad
[
prefix
]
=
int
(
rad
)
radUint
:=
uint64
(
rad
)
*
((^
uint64
(
0
))
/
1000000
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
y
:=
sort
.
Search
(
ys
,
func
(
i
int
)
bool
{
return
nodes
[
i
]
>
radUint
})
set
(
pic
,
x
,
y
,
1
,
255
)
}
}
if
w
==
"*MR"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
scanner
.
Scan
()
scanner
.
Scan
()
rad
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
radUint
:=
uint64
(
rad
)
*
((^
uint64
(
0
))
/
1000000
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
y
:=
sort
.
Search
(
ys
,
func
(
i
int
)
bool
{
return
nodes
[
i
]
>
radUint
})
set
(
pic
,
x
,
y
,
0
,
255
)
}
if
w
==
"*W"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
scanner
.
Scan
()
wp
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
y
:=
nodeIdx
[
prefix
]
set
(
pic2
,
x
,
y
,
0
,
int
(
wp
/
100000
))
set
(
pic2
,
x
,
y
,
1
,
int
(
wp
/
10000
))
set
(
pic2
,
x
,
y
,
2
,
int
(
wp
/
1000
))
}
if
w
==
"*+"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
y
:=
nodeIdx
[
prefix
]
set
(
pic
,
x
,
y
,
2
,
255
)
scanner
.
Scan
()
}
}
f
.
Close
()
f
,
_
=
os
.
Create
(
"test.png"
)
w
:=
bufio
.
NewWriter
(
f
)
png
.
Encode
(
w
,
pic
)
w
.
Flush
()
f
.
Close
()
f
,
_
=
os
.
Create
(
"test2.png"
)
w
=
bufio
.
NewWriter
(
f
)
png
.
Encode
(
w
,
pic2
)
w
.
Flush
()
f
.
Close
()
}
type
uint64Slice
[]
uint64
//
Len
is
the
number
of
elements
in
the
collection
.
func
(
s
uint64Slice
)
Len
()
int
{
return
len
(
s
)
}
//
Less
reports
whether
the
element
with
//
index
i
should
sort
before
the
element
with
index
j
.
func
(
s
uint64Slice
)
Less
(
i
,
j
int
)
bool
{
return
s
[
i
]
<
s
[
j
]
}
//
Swap
swaps
the
elements
with
indexes
i
and
j
.
func
(
s
uint64Slice
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
p2p/discv5/testimg/testimg.1
deleted
100644 → 0
View file @
49da4298
package
main
import
(
"bufio"
"encoding/binary"
"fmt"
"image"
"image/png"
"os"
"sort"
"strconv"
"github.com/ethereum/go-ethereum/crypto"
)
var
xs
,
ys
,
maxTime
int
func
set
(
pic
*
image
.
NRGBA
,
x
,
y
,
c
,
v
int
)
{
if
v
>
255
{
v
=
255
}
if
x
>=
0
&&
x
<
xs
&&
y
>=
0
&&
y
<
ys
{
pic
.
Pix
[
y
*
pic
.
Stride
+
x
*
4
+
c
]
=
uint8
(
v
)
}
}
func
main
()
{
var
nodes
uint64Slice
inputFile
:=
"test.out"
if
len
(
os
.
Args
)
>
1
{
inputFile
=
os
.
Args
[
1
]
}
topic
:=
"foo"
if
len
(
os
.
Args
)
>
2
{
topic
=
os
.
Args
[
2
]
}
topicHash
:=
crypto
.
Keccak256Hash
([]
byte
(
topic
))
fmt
.
Println
(
topicHash
)
topicPrefix
:=
binary
.
BigEndian
.
Uint64
(
topicHash
[:
8
])
f
,
_
:=
os
.
Open
(
inputFile
)
scanner
:=
bufio
.
NewScanner
(
f
)
scanner
.
Split
(
bufio
.
ScanWords
)
for
scanner
.
Scan
()
{
w
:=
scanner
.
Text
()
if
w
==
"*N"
{
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
nodes
=
append
(
nodes
,
prefix
^
topicPrefix
)
}
if
w
==
"*R"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
if
int
(
time
)
>
maxTime
{
maxTime
=
int
(
time
)
}
}
}
f
.
Close
()
sort
.
Sort
(
nodes
)
nodeIdx
:=
make
(
map
[
uint64
]
int
)
for
i
,
v
:=
range
nodes
{
nodeIdx
[
v
^
topicPrefix
]
=
i
}
xs
=
maxTime
/
10000
ys
=
len
(
nodes
)
pic
:=
image
.
NewNRGBA
(
image
.
Rect
(
0
,
0
,
xs
,
ys
))
for
y
:=
0
;
y
<
ys
;
y
++
{
for
x
:=
0
;
x
<
xs
;
x
++
{
set
(
pic
,
x
,
y
,
3
,
255
)
}
}
pic2
:=
image
.
NewNRGBA
(
image
.
Rect
(
0
,
0
,
xs
,
ys
))
for
y
:=
0
;
y
<
ys
;
y
++
{
for
x
:=
0
;
x
<
xs
;
x
++
{
set
(
pic2
,
x
,
y
,
3
,
255
)
}
}
f
,
_
=
os
.
Open
(
inputFile
)
scanner
=
bufio
.
NewScanner
(
f
)
scanner
.
Split
(
bufio
.
ScanWords
)
nodeRad
:=
make
(
map
[
uint64
]
int
)
for
scanner
.
Scan
()
{
w
:=
scanner
.
Text
()
if
w
==
"*R"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
scanner
.
Scan
()
if
scanner
.
Text
()
==
topic
{
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
scanner
.
Scan
()
rad
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
if
int
(
rad
)
!= nodeRad[prefix] {
nodeRad
[
prefix
]
=
int
(
rad
)
radUint
:=
uint64
(
rad
)
*
((^
uint64
(
0
))
/
1000000
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
y
:=
sort
.
Search
(
ys
,
func
(
i
int
)
bool
{
return
nodes
[
i
]
>
radUint
})
set
(
pic
,
x
,
y
,
1
,
255
)
}
}
}
if
w
==
"*MR"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
scanner
.
Scan
()
if
scanner
.
Text
()
==
topic
{
scanner
.
Scan
()
scanner
.
Scan
()
rad
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
radUint
:=
uint64
(
rad
)
*
((^
uint64
(
0
))
/
1000000
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
y
:=
sort
.
Search
(
ys
,
func
(
i
int
)
bool
{
return
nodes
[
i
]
>
radUint
})
set
(
pic
,
x
,
y
,
0
,
255
)
}
}
if
w
==
"*W"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
scanner
.
Scan
()
if
scanner
.
Text
()
==
topic
{
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
scanner
.
Scan
()
wp
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
y
:=
nodeIdx
[
prefix
]
set
(
pic2
,
x
,
y
,
0
,
int
(
wp
/
100000
))
set
(
pic2
,
x
,
y
,
1
,
int
(
wp
/
10000
))
set
(
pic2
,
x
,
y
,
2
,
int
(
wp
/
1000
))
}
}
if
w
==
"*+"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
scanner
.
Scan
()
if
scanner
.
Text
()
==
topic
{
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
y
:=
nodeIdx
[
prefix
]
set
(
pic
,
x
,
y
,
2
,
255
)
scanner
.
Scan
()
}
}
}
f
.
Close
()
f
,
_
=
os
.
Create
(
"test.png"
)
w
:=
bufio
.
NewWriter
(
f
)
png
.
Encode
(
w
,
pic
)
w
.
Flush
()
f
.
Close
()
f
,
_
=
os
.
Create
(
"test2.png"
)
w
=
bufio
.
NewWriter
(
f
)
png
.
Encode
(
w
,
pic2
)
w
.
Flush
()
f
.
Close
()
}
type
uint64Slice
[]
uint64
//
Len
is
the
number
of
elements
in
the
collection
.
func
(
s
uint64Slice
)
Len
()
int
{
return
len
(
s
)
}
//
Less
reports
whether
the
element
with
//
index
i
should
sort
before
the
element
with
index
j
.
func
(
s
uint64Slice
)
Less
(
i
,
j
int
)
bool
{
return
s
[
i
]
<
s
[
j
]
}
//
Swap
swaps
the
elements
with
indexes
i
and
j
.
func
(
s
uint64Slice
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
p2p/discv5/testimg/testimg.go
deleted
100644 → 0
View file @
49da4298
package
main
import
(
"bufio"
"encoding/binary"
"fmt"
"image"
"image/png"
"math"
"os"
"sort"
"strconv"
"github.com/ethereum/go-ethereum/crypto"
)
var
xs
,
ys
,
maxTime
int
var
minAbsTime
,
maxAbsTime
int64
func
set
(
pic
*
image
.
NRGBA
,
x
,
y
,
c
,
v
int
)
{
if
v
>
255
{
v
=
255
}
if
x
>=
0
&&
x
<
xs
&&
y
>=
0
&&
y
<
ys
{
pic
.
Pix
[
y
*
pic
.
Stride
+
x
*
4
+
c
]
=
uint8
(
v
)
}
}
type
nodeStats
[]
struct
{
wpSum
,
wpCnt
,
wpXcnt
,
regCnt
,
regXcnt
uint64
}
type
nodeInfo
struct
{
maxMR
int
topics
map
[
string
]
struct
{}
}
const
(
regStatDiv
=
60
regStatYdiv
=
30
)
type
topicInfo
struct
{
prefix
uint64
nodes
uint64Slice
nodeStats
nodeStats
nodeIdx
map
[
uint64
]
int
pic
,
pic2
*
image
.
NRGBA
nodeRad
map
[
uint64
]
int
regStats
[]
int
}
func
main
()
{
var
nodes
uint64Slice
topics
:=
make
(
map
[
string
]
*
topicInfo
)
inputFile
:=
"test.out"
if
len
(
os
.
Args
)
>
1
{
inputFile
=
os
.
Args
[
1
]
}
f
,
_
:=
os
.
Open
(
inputFile
)
scanner
:=
bufio
.
NewScanner
(
f
)
scanner
.
Split
(
bufio
.
ScanWords
)
minAbsTime
=
math
.
MaxInt64
for
scanner
.
Scan
()
{
w
:=
scanner
.
Text
()
if
w
==
"*N"
{
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
nodes
=
append
(
nodes
,
prefix
)
}
if
w
==
"*R"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
if
time
>
maxAbsTime
{
maxAbsTime
=
time
}
if
time
<
minAbsTime
{
minAbsTime
=
time
}
scanner
.
Scan
()
topic
:=
scanner
.
Text
()
if
_
,
ok
:=
topics
[
topic
];
!
ok
{
fmt
.
Println
(
topic
)
topicHash
:=
crypto
.
Keccak256Hash
([]
byte
(
topic
))
topics
[
topic
]
=
&
topicInfo
{
prefix
:
binary
.
BigEndian
.
Uint64
(
topicHash
[
:
8
])}
}
}
}
f
.
Close
()
maxTime
=
int
(
maxAbsTime
-
minAbsTime
)
xs
=
maxTime
/
10000
ys
=
len
(
nodes
)
nodeIdx
:=
make
(
map
[
uint64
]
int
)
for
i
,
v
:=
range
nodes
{
nodeIdx
[
v
]
=
i
}
nodeInfo
:=
make
([]
nodeInfo
,
len
(
nodes
))
for
_
,
t
:=
range
topics
{
t
.
nodes
=
make
(
uint64Slice
,
len
(
nodes
))
t
.
nodeStats
=
make
(
nodeStats
,
len
(
nodes
))
for
i
,
v
:=
range
nodes
{
t
.
nodes
[
i
]
=
v
^
t
.
prefix
}
sort
.
Sort
(
t
.
nodes
)
t
.
nodeIdx
=
make
(
map
[
uint64
]
int
)
for
i
,
v
:=
range
t
.
nodes
{
t
.
nodeIdx
[
v
^
t
.
prefix
]
=
i
}
t
.
pic
=
image
.
NewNRGBA
(
image
.
Rect
(
0
,
0
,
xs
,
ys
))
for
y
:=
0
;
y
<
ys
;
y
++
{
for
x
:=
0
;
x
<
xs
;
x
++
{
set
(
t
.
pic
,
x
,
y
,
3
,
255
)
}
}
t
.
pic2
=
image
.
NewNRGBA
(
image
.
Rect
(
0
,
0
,
xs
,
ys
))
for
y
:=
0
;
y
<
ys
;
y
++
{
for
x
:=
0
;
x
<
xs
;
x
++
{
set
(
t
.
pic2
,
x
,
y
,
3
,
255
)
}
}
t
.
nodeRad
=
make
(
map
[
uint64
]
int
)
t
.
regStats
=
make
([]
int
,
xs
/
regStatDiv
+
1
)
}
f
,
_
=
os
.
Open
(
inputFile
)
scanner
=
bufio
.
NewScanner
(
f
)
scanner
.
Split
(
bufio
.
ScanWords
)
statBegin
:=
int64
(
40000000
)
statEnd
:=
int64
(
maxTime
-
10000000
)
for
scanner
.
Scan
()
{
w
:=
scanner
.
Text
()
if
w
==
"*R"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
time
-=
minAbsTime
scanner
.
Scan
()
t
:=
topics
[
scanner
.
Text
()]
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
scanner
.
Scan
()
rad
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
if
int
(
rad
)
!=
t
.
nodeRad
[
prefix
]
{
t
.
nodeRad
[
prefix
]
=
int
(
rad
)
radUint
:=
uint64
(
rad
)
*
((
^
uint64
(
0
))
/
1000000
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
y
:=
sort
.
Search
(
ys
,
func
(
i
int
)
bool
{
return
t
.
nodes
[
i
]
>
radUint
})
set
(
t
.
pic
,
x
,
y
,
1
,
255
)
}
}
if
w
==
"*MR"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
time
-=
minAbsTime
scanner
.
Scan
()
topic
:=
scanner
.
Text
()
t
:=
topics
[
topic
]
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
scanner
.
Scan
()
rad
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
radUint
:=
uint64
(
rad
)
*
((
^
uint64
(
0
))
/
1000000
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
y
:=
sort
.
Search
(
ys
,
func
(
i
int
)
bool
{
return
t
.
nodes
[
i
]
>
radUint
})
set
(
t
.
pic
,
x
,
y
,
0
,
255
)
ni
:=
nodeInfo
[
nodeIdx
[
prefix
]]
if
int
(
rad
)
>
ni
.
maxMR
{
ni
.
maxMR
=
int
(
rad
)
if
ni
.
topics
==
nil
{
ni
.
topics
=
make
(
map
[
string
]
struct
{})
}
ni
.
topics
[
topic
]
=
struct
{}{}
}
nodeInfo
[
nodeIdx
[
prefix
]]
=
ni
}
if
w
==
"*W"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
time
-=
minAbsTime
scanner
.
Scan
()
t
:=
topics
[
scanner
.
Text
()]
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
scanner
.
Scan
()
wp
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
y
:=
t
.
nodeIdx
[
prefix
]
if
time
>=
statBegin
&&
time
<
statEnd
{
t
.
nodeStats
[
y
]
.
wpSum
+=
uint64
(
wp
)
if
wp
>=
600000
{
t
.
nodeStats
[
y
]
.
wpXcnt
++
}
t
.
nodeStats
[
y
]
.
wpCnt
++
}
/*set(t.pic2, x, y, 0, int(wp/100000))
set(t.pic2, x, y, 1, int(wp/10000))
set(t.pic2, x, y, 2, int(wp/1000))*/
if
wp
>=
1800000
{
set
(
t
.
pic2
,
x
,
y
,
0
,
255
)
}
if
wp
>=
600000
{
set
(
t
.
pic2
,
x
,
y
,
1
,
255
)
}
if
wp
>=
60000
{
set
(
t
.
pic2
,
x
,
y
,
2
,
255
)
}
}
if
w
==
"*+"
{
scanner
.
Scan
()
time
,
_
:=
strconv
.
ParseInt
(
scanner
.
Text
(),
10
,
64
)
time
-=
minAbsTime
scanner
.
Scan
()
t
:=
topics
[
scanner
.
Text
()]
scanner
.
Scan
()
prefix
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
x
:=
int
(
time
*
int64
(
xs
)
/
int64
(
maxTime
))
if
x
<
xs
{
t
.
regStats
[
x
/
regStatDiv
]
++
}
y
:=
t
.
nodeIdx
[
prefix
]
set
(
t
.
pic
,
x
,
y
,
2
,
255
)
scanner
.
Scan
()
prefix2
,
_
:=
strconv
.
ParseUint
(
scanner
.
Text
(),
16
,
64
)
y2
:=
t
.
nodeIdx
[
prefix2
]
if
time
>=
statBegin
&&
time
<
statEnd
{
t
.
nodeStats
[
y
]
.
regCnt
++
t
.
nodeStats
[
y2
]
.
regXcnt
++
}
}
}
f
.
Close
()
for
tt
,
t
:=
range
topics
{
f
,
_
=
os
.
Create
(
"test_"
+
tt
+
".png"
)
w
:=
bufio
.
NewWriter
(
f
)
png
.
Encode
(
w
,
t
.
pic
)
w
.
Flush
()
f
.
Close
()
for
x
:=
0
;
x
<
xs
;
x
++
{
yy
:=
t
.
regStats
[
x
/
regStatDiv
]
/
regStatYdiv
if
yy
>
ys
{
yy
=
ys
}
for
y
:=
0
;
y
<
yy
;
y
++
{
set
(
t
.
pic2
,
x
,
ys
-
1
-
y
,
1
,
255
)
}
}
f
,
_
=
os
.
Create
(
"test2_"
+
tt
+
".png"
)
w
=
bufio
.
NewWriter
(
f
)
png
.
Encode
(
w
,
t
.
pic2
)
w
.
Flush
()
f
.
Close
()
if
statEnd
>
statBegin
{
xxs
:=
len
(
t
.
nodeStats
)
yys
:=
1000
yyh
:=
yys
/
2
pic3
:=
image
.
NewNRGBA
(
image
.
Rect
(
0
,
0
,
xxs
,
yys
))
for
y
:=
0
;
y
<
yys
;
y
++
{
for
x
:=
0
;
x
<
xxs
;
x
++
{
set
(
pic3
,
x
,
y
,
3
,
255
)
}
}
for
x
:=
0
;
x
<
xxs
;
x
++
{
wpy
:=
0
if
t
.
nodeStats
[
x
]
.
wpCnt
>
0
{
// wpy = int(t.nodeStats[x].wpSum / t.nodeStats[x].wpCnt / 10000)
wpy
=
int
(
uint64
(
yyh
)
*
t
.
nodeStats
[
x
]
.
wpXcnt
/
t
.
nodeStats
[
x
]
.
wpCnt
)
}
if
wpy
>
yyh
{
wpy
=
yyh
}
for
y
:=
0
;
y
<
wpy
;
y
++
{
set
(
pic3
,
x
,
yys
-
1
-
y
,
1
,
255
)
}
regy
:=
int
(
t
.
nodeStats
[
x
]
.
regCnt
*
2400000
/
uint64
(
statEnd
-
statBegin
))
if
regy
>
yyh
{
regy
=
yyh
}
for
y
:=
0
;
y
<
regy
;
y
++
{
set
(
pic3
,
x
,
yyh
-
1
-
y
,
2
,
255
)
}
regy2
:=
int
(
t
.
nodeStats
[
x
]
.
regXcnt
*
2400000
/
uint64
(
statEnd
-
statBegin
))
if
regy2
>
yyh
{
regy2
=
yyh
}
for
y
:=
0
;
y
<
regy2
;
y
++
{
set
(
pic3
,
x
,
yyh
-
1
-
y
,
0
,
255
)
}
}
f
,
_
=
os
.
Create
(
"test3_"
+
tt
+
".png"
)
w
=
bufio
.
NewWriter
(
f
)
png
.
Encode
(
w
,
pic3
)
w
.
Flush
()
f
.
Close
()
}
}
for
i
,
ni
:=
range
nodeInfo
{
fmt
.
Printf
(
"%d %016x maxMR = %d "
,
i
,
nodes
[
i
],
ni
.
maxMR
)
for
t
,
_
:=
range
ni
.
topics
{
fmt
.
Printf
(
" %s"
,
t
)
}
fmt
.
Println
()
}
}
type
uint64Slice
[]
uint64
// Len is the number of elements in the collection.
func
(
s
uint64Slice
)
Len
()
int
{
return
len
(
s
)
}
// Less reports whether the element with
// index i should sort before the element with index j.
func
(
s
uint64Slice
)
Less
(
i
,
j
int
)
bool
{
return
s
[
i
]
<
s
[
j
]
}
// Swap swaps the elements with indexes i and j.
func
(
s
uint64Slice
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
p2p/discv5/ticket.go
View file @
0f19cbc6
...
@@ -766,10 +766,26 @@ func (r *topicRadius) targetForBucket(bucket int) common.Hash {
...
@@ -766,10 +766,26 @@ func (r *topicRadius) targetForBucket(bucket int) common.Hash {
prefix
:=
r
.
topicHashPrefix
^
xor
prefix
:=
r
.
topicHashPrefix
^
xor
var
target
common
.
Hash
var
target
common
.
Hash
binary
.
BigEndian
.
PutUint64
(
target
[
0
:
8
],
prefix
)
binary
.
BigEndian
.
PutUint64
(
target
[
0
:
8
],
prefix
)
rand
.
Read
(
target
[
8
:
])
globalRand
Read
(
target
[
8
:
])
return
target
return
target
}
}
// package rand provides a Read function in Go 1.6 and later, but
// we can't use it yet because we still support Go 1.5.
func
globalRandRead
(
b
[]
byte
)
{
pos
:=
0
val
:=
0
for
n
:=
0
;
n
<
len
(
b
);
n
++
{
if
pos
==
0
{
val
=
rand
.
Int
()
pos
=
7
}
b
[
n
]
=
byte
(
val
)
val
>>=
8
pos
--
}
}
func
(
r
*
topicRadius
)
isInRadius
(
addrHash
common
.
Hash
)
bool
{
func
(
r
*
topicRadius
)
isInRadius
(
addrHash
common
.
Hash
)
bool
{
nodePrefix
:=
binary
.
BigEndian
.
Uint64
(
addrHash
[
0
:
8
])
nodePrefix
:=
binary
.
BigEndian
.
Uint64
(
addrHash
[
0
:
8
])
dist
:=
nodePrefix
^
r
.
topicHashPrefix
dist
:=
nodePrefix
^
r
.
topicHashPrefix
...
@@ -926,7 +942,7 @@ func (r *topicRadius) nextTarget(forceRegular bool) lookupInfo {
...
@@ -926,7 +942,7 @@ func (r *topicRadius) nextTarget(forceRegular bool) lookupInfo {
prefix
:=
r
.
topicHashPrefix
^
rnd
prefix
:=
r
.
topicHashPrefix
^
rnd
var
target
common
.
Hash
var
target
common
.
Hash
binary
.
BigEndian
.
PutUint64
(
target
[
0
:
8
],
prefix
)
binary
.
BigEndian
.
PutUint64
(
target
[
0
:
8
],
prefix
)
rand
.
Read
(
target
[
8
:
])
globalRand
Read
(
target
[
8
:
])
return
lookupInfo
{
target
:
target
,
topic
:
r
.
topic
,
radiusLookup
:
false
}
return
lookupInfo
{
target
:
target
,
topic
:
r
.
topic
,
radiusLookup
:
false
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment