Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
89583030
Commit
89583030
authored
Sep 12, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
339f3e1c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
9 deletions
+42
-9
go/neo/t/zhash.go
go/neo/t/zhash.go
+28
-9
go/neo/t/zhash.py
go/neo/t/zhash.py
+14
-0
No files found.
go/neo/t/zhash.go
View file @
89583030
...
@@ -33,16 +33,32 @@ type hasher struct {
...
@@ -33,16 +33,32 @@ type hasher struct {
name
string
name
string
}
}
// hasher that discards data
type
nullHasher
struct
{}
func
(
h
nullHasher
)
Write
(
b
[]
byte
)
(
int
,
error
)
{
return
len
(
b
),
nil
}
func
(
h
nullHasher
)
Sum
(
b
[]
byte
)
[]
byte
{
return
[]
byte
{
0
}
}
func
(
h
nullHasher
)
Reset
()
{}
func
(
h
nullHasher
)
Size
()
int
{
return
1
}
func
(
h
nullHasher
)
BlockSize
()
int
{
return
1
}
func
main
()
{
func
main
()
{
defer
log
.
Flush
()
defer
log
.
Flush
()
fadler32
:=
flag
.
Bool
(
"adler32"
,
false
,
"compute Adler32 checksum"
)
fnull
:=
flag
.
Bool
(
"null"
,
false
,
"don't compute hash - just read data"
)
fadler32
:=
flag
.
Bool
(
"adler32"
,
false
,
"compute Adler32 checksum"
)
fcrc32
:=
flag
.
Bool
(
"crc32"
,
false
,
"compute CRC32 checksum"
)
fcrc32
:=
flag
.
Bool
(
"crc32"
,
false
,
"compute CRC32 checksum"
)
fsha1
:=
flag
.
Bool
(
"sha1"
,
false
,
"compute SHA1 cryptographic hash"
)
fsha1
:=
flag
.
Bool
(
"sha1"
,
false
,
"compute SHA1 cryptographic hash"
)
fsha256
:=
flag
.
Bool
(
"sha256"
,
false
,
"compute SHA256 cryptographic hash"
)
fsha256
:=
flag
.
Bool
(
"sha256"
,
false
,
"compute SHA256 cryptographic hash"
)
fsha512
:=
flag
.
Bool
(
"sha512"
,
false
,
"compute SHA512 cryptographic hash"
)
fsha512
:=
flag
.
Bool
(
"sha512"
,
false
,
"compute SHA512 cryptographic hash"
)
useprefetch
:=
flag
.
Bool
(
"useprefetch"
,
false
,
"prefetch loaded objects"
)
useprefetch
:=
flag
.
Bool
(
"useprefetch"
,
false
,
"prefetch loaded objects"
)
flag
.
Parse
()
flag
.
Parse
()
url
:=
flag
.
Args
()[
0
]
// XXX dirty
if
flag
.
NArg
()
!=
1
{
flag
.
Usage
()
// XXX exit
}
url
:=
flag
.
Arg
(
0
)
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
...
@@ -57,6 +73,7 @@ func main() {
...
@@ -57,6 +73,7 @@ func main() {
}
}
switch
{
switch
{
case
*
fnull
:
inith
(
"null"
,
func
()
hash
.
Hash
{
return
nullHasher
{}
})
case
*
fadler32
:
inith
(
"adler32"
,
func
()
hash
.
Hash
{
return
adler32
.
New
()
})
case
*
fadler32
:
inith
(
"adler32"
,
func
()
hash
.
Hash
{
return
adler32
.
New
()
})
case
*
fcrc32
:
inith
(
"crc32"
,
func
()
hash
.
Hash
{
return
crc32
.
NewIEEE
()
})
case
*
fcrc32
:
inith
(
"crc32"
,
func
()
hash
.
Hash
{
return
crc32
.
NewIEEE
()
})
case
*
fsha1
:
inith
(
"sha1"
,
sha1
.
New
)
case
*
fsha1
:
inith
(
"sha1"
,
sha1
.
New
)
...
@@ -99,7 +116,7 @@ func zhash(ctx context.Context, url string, h hasher, useprefetch bool) (err err
...
@@ -99,7 +116,7 @@ func zhash(ctx context.Context, url string, h hasher, useprefetch bool) (err err
}
}
}
}
load
:=
func
(
ctx
context
.
Context
,
xid
zodb
.
Xid
)
(
[]
byte
,
zodb
.
Tid
,
error
)
{
load
:=
func
(
ctx
context
.
Context
,
xid
zodb
.
Xid
)
(
*
zodb
.
Buf
,
zodb
.
Tid
,
error
)
{
if
cache
!=
nil
{
if
cache
!=
nil
{
return
cache
.
Load
(
ctx
,
xid
)
return
cache
.
Load
(
ctx
,
xid
)
}
else
{
}
else
{
...
@@ -158,7 +175,7 @@ loop:
...
@@ -158,7 +175,7 @@ loop:
if
xid
.
Oid
%
8
==
0
{
if
xid
.
Oid
%
8
==
0
{
prefetchBlk
(
ctx
,
xid
)
prefetchBlk
(
ctx
,
xid
)
}
}
data
,
_
,
err
:=
load
(
ctx
,
xid
)
buf
,
_
,
err
:=
load
(
ctx
,
xid
)
switch
err
.
(
type
)
{
switch
err
.
(
type
)
{
case
nil
:
case
nil
:
// ok
// ok
...
@@ -168,13 +185,15 @@ loop:
...
@@ -168,13 +185,15 @@ loop:
return
err
return
err
}
}
h
.
Write
(
d
ata
)
h
.
Write
(
buf
.
D
ata
)
//fmt.Fprintf(os.Stderr, "%d @%s\tsha1: %x\n", uint(oid), serial, h.Sum(nil))
//fmt.Fprintf(os.Stderr, "%d @%s\tsha1: %x\n", uint(oid), serial, h.Sum(nil))
//fmt.Fprintf(os.Stderr, "\tdata: %x\n",
d
ata)
//fmt.Fprintf(os.Stderr, "\tdata: %x\n",
buf.D
ata)
nread
+=
len
(
d
ata
)
nread
+=
len
(
buf
.
D
ata
)
oid
+=
1
oid
+=
1
buf
.
Free
()
}
}
tend
:=
time
.
Now
()
tend
:=
time
.
Now
()
...
...
go/neo/t/zhash.py
View file @
89583030
...
@@ -14,6 +14,16 @@ import sys
...
@@ -14,6 +14,16 @@ import sys
from
time
import
time
from
time
import
time
from
getopt
import
getopt
,
GetoptError
from
getopt
import
getopt
,
GetoptError
# hasher that discards data
class
NullHasher
:
name
=
"null"
def
update
(
self
,
data
):
pass
def
hexdigest
(
self
):
return
"00"
# adler32 in hashlib interface
# adler32 in hashlib interface
class
Adler32Hasher
:
class
Adler32Hasher
:
name
=
"adler32"
name
=
"adler32"
...
@@ -42,6 +52,7 @@ class CRC32Hasher:
...
@@ -42,6 +52,7 @@ class CRC32Hasher:
# {} name -> hasher
# {} name -> hasher
hashRegistry
=
{
hashRegistry
=
{
"null"
:
NullHasher
,
"adler32"
:
Adler32Hasher
,
"adler32"
:
Adler32Hasher
,
"crc32"
:
CRC32Hasher
,
"crc32"
:
CRC32Hasher
,
"sha1"
:
hashlib
.
sha1
,
"sha1"
:
hashlib
.
sha1
,
...
@@ -55,6 +66,7 @@ def usage(w):
...
@@ -55,6 +66,7 @@ def usage(w):
options:
options:
--null don't compute hash - just read data
--adler32 compute Adler32 checksum
--adler32 compute Adler32 checksum
--crc32 compute CRC32 checksum
--crc32 compute CRC32 checksum
--sha1 compute SHA1 cryptographic hash
--sha1 compute SHA1 cryptographic hash
...
@@ -72,6 +84,7 @@ def main():
...
@@ -72,6 +84,7 @@ def main():
for
opt
,
_
in
optv
:
for
opt
,
_
in
optv
:
if
opt
in
(
"-h"
,
"--help"
):
if
opt
in
(
"-h"
,
"--help"
):
print
(
__doc__
)
usage
(
sys
.
stdout
)
usage
(
sys
.
stdout
)
sys
.
exit
()
sys
.
exit
()
...
@@ -80,6 +93,7 @@ def main():
...
@@ -80,6 +93,7 @@ def main():
h
=
hctor
()
h
=
hctor
()
if
len
(
argv
)
!=
1
:
if
len
(
argv
)
!=
1
:
print
(
__doc__
)
usage
(
sys
.
stderr
)
usage
(
sys
.
stderr
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
...
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