Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
d91b419e
Commit
d91b419e
authored
Dec 06, 2015
by
Jeromy
Browse files
WIP
parent
a40ef343
Changes
365
Hide whitespace changes
Inline
Side-by-side
Too many changes to show.
To preserve performance only
365 of 365+
files are displayed.
Plain diff
Email patch
vendor/gx/QmRmT6MSnfhRDW1PTUGSd3z4fqXK48GUequQAZzeT4c5iC/go-stream-muxer/spdystream/spdystream.go
deleted
100644 → 0
View file @
a40ef343
package
peerstream_spdystream
import
(
"errors"
"net"
"net/http"
smux
"gx/QmRmT6MSnfhRDW1PTUGSd3z4fqXK48GUequQAZzeT4c5iC/go-stream-muxer"
ss
"gx/QmRCCpiiYnh621p5Qntvem8pR3Wks8WPMTnEMaAi2oddW2/spdystream"
)
var
ErrUseServe
=
errors
.
New
(
"not implemented, use Serve"
)
// stream implements smux.Stream using a ss.Stream
type
stream
ss
.
Stream
func
(
s
*
stream
)
spdyStream
()
*
ss
.
Stream
{
return
(
*
ss
.
Stream
)(
s
)
}
func
(
s
*
stream
)
Read
(
buf
[]
byte
)
(
int
,
error
)
{
return
s
.
spdyStream
()
.
Read
(
buf
)
}
func
(
s
*
stream
)
Write
(
buf
[]
byte
)
(
int
,
error
)
{
return
s
.
spdyStream
()
.
Write
(
buf
)
}
func
(
s
*
stream
)
Close
()
error
{
// Reset is spdystream's full bidirectional close.
// We expose bidirectional close as our `Close`.
// To close only half of the connection, and use other
// spdystream options, just get the stream with:
// ssStream := (*ss.Stream)(stream)
return
s
.
spdyStream
()
.
Reset
()
}
// Conn is a connection to a remote peer.
type
conn
struct
{
sc
*
ss
.
Connection
closed
chan
struct
{}
}
func
(
c
*
conn
)
spdyConn
()
*
ss
.
Connection
{
return
c
.
sc
}
func
(
c
*
conn
)
Close
()
error
{
err
:=
c
.
spdyConn
()
.
CloseWait
()
if
!
c
.
IsClosed
()
{
close
(
c
.
closed
)
}
return
err
}
func
(
c
*
conn
)
IsClosed
()
bool
{
select
{
case
<-
c
.
closed
:
return
true
case
<-
c
.
sc
.
CloseChan
()
:
return
true
default
:
return
false
}
}
// OpenStream creates a new stream.
func
(
c
*
conn
)
OpenStream
()
(
smux
.
Stream
,
error
)
{
s
,
err
:=
c
.
spdyConn
()
.
CreateStream
(
http
.
Header
{
":method"
:
[]
string
{
"GET"
},
// this is here for HTTP/SPDY interop
":path"
:
[]
string
{
"/"
},
// this is here for HTTP/SPDY interop
},
nil
,
false
)
if
err
!=
nil
{
return
nil
,
err
}
// wait for a response before writing. for some reason
// spdystream does not make forward progress unless you do this.
s
.
Wait
()
return
(
*
stream
)(
s
),
nil
}
// AcceptStream accepts a stream opened by the other side.
func
(
c
*
conn
)
AcceptStream
()
(
smux
.
Stream
,
error
)
{
return
nil
,
ErrUseServe
}
// Serve starts listening for incoming requests and handles them
// using given StreamHandler
func
(
c
*
conn
)
Serve
(
handler
smux
.
StreamHandler
)
{
c
.
spdyConn
()
.
Serve
(
func
(
s
*
ss
.
Stream
)
{
// Flow control and backpressure of Opening streams is broken.
// I believe that spdystream has one set of workers that both send
// data AND accept new streams (as it's just more data). there
// is a problem where if the new stream handlers want to throttle,
// they also eliminate the ability to read/write data, which makes
// forward-progress impossible. Thus, throttling this function is
// -- at this moment -- not the solution. Either spdystream must
// change, or we must throttle another way. go-peerstream handles
// every new stream in its own goroutine.
err
:=
s
.
SendReply
(
http
.
Header
{},
false
)
if
err
!=
nil
{
// this _could_ error out. not sure how to handle this failure.
// don't return, and let the caller handle a broken stream.
// better than _hiding_ an error.
// return
}
go
handler
((
*
stream
)(
s
))
})
}
type
transport
struct
{}
// Transport is a go-peerstream transport that constructs
// spdystream-backed connections.
var
Transport
=
transport
{}
func
(
t
transport
)
NewConn
(
nc
net
.
Conn
,
isServer
bool
)
(
smux
.
Conn
,
error
)
{
sc
,
err
:=
ss
.
NewConnection
(
nc
,
isServer
)
return
&
conn
{
sc
:
sc
,
closed
:
make
(
chan
struct
{})},
err
}
vendor/gx/QmRmT6MSnfhRDW1PTUGSd3z4fqXK48GUequQAZzeT4c5iC/go-stream-muxer/spdystream/spdystream_test.go
deleted
100644 → 0
View file @
a40ef343
package
peerstream_spdystream
import
(
"testing"
test
"gx/QmRmT6MSnfhRDW1PTUGSd3z4fqXK48GUequQAZzeT4c5iC/go-stream-muxer/test"
)
func
TestSpdyStreamTransport
(
t
*
testing
.
T
)
{
test
.
SubtestAll
(
t
,
Transport
)
}
vendor/gx/QmRmT6MSnfhRDW1PTUGSd3z4fqXK48GUequQAZzeT4c5iC/go-stream-muxer/test/ttest.go
deleted
100644 → 0
View file @
a40ef343
package
sm_test
import
(
"bytes"
crand
"crypto/rand"
"fmt"
"io"
mrand
"math/rand"
"net"
"os"
"reflect"
"runtime"
"runtime/debug"
"sync"
"testing"
smux
"gx/QmRmT6MSnfhRDW1PTUGSd3z4fqXK48GUequQAZzeT4c5iC/go-stream-muxer"
)
var
randomness
[]
byte
func
init
()
{
// read 1MB of randomness
randomness
=
make
([]
byte
,
1
<<
20
)
if
_
,
err
:=
crand
.
Read
(
randomness
);
err
!=
nil
{
panic
(
err
)
}
}
type
Options
struct
{
tr
smux
.
Transport
connNum
int
streamNum
int
msgNum
int
msgMin
int
msgMax
int
}
func
randBuf
(
size
int
)
[]
byte
{
n
:=
len
(
randomness
)
-
size
if
size
<
1
{
panic
(
fmt
.
Errorf
(
"requested too large buffer (%d). max is %d"
,
size
,
len
(
randomness
)))
}
start
:=
mrand
.
Intn
(
n
)
return
randomness
[
start
:
start
+
size
]
}
func
checkErr
(
t
*
testing
.
T
,
err
error
)
{
if
err
!=
nil
{
debug
.
PrintStack
()
t
.
Fatal
(
err
)
}
}
func
log
(
s
string
,
v
...
interface
{})
{
if
testing
.
Verbose
()
{
fmt
.
Fprintf
(
os
.
Stderr
,
"> "
+
s
+
"
\n
"
,
v
...
)
}
}
func
echoStream
(
s
smux
.
Stream
)
{
defer
s
.
Close
()
log
(
"accepted stream"
)
io
.
Copy
(
&
LogWriter
{
s
},
s
)
// echo everything
log
(
"closing stream"
)
}
type
LogWriter
struct
{
W
io
.
Writer
}
func
(
lw
*
LogWriter
)
Write
(
buf
[]
byte
)
(
int
,
error
)
{
if
testing
.
Verbose
()
{
log
(
"logwriter: writing %d bytes"
,
len
(
buf
))
}
return
lw
.
W
.
Write
(
buf
)
}
func
GoServe
(
t
*
testing
.
T
,
tr
smux
.
Transport
,
l
net
.
Listener
)
(
done
func
())
{
closed
:=
make
(
chan
struct
{},
1
)
go
func
()
{
for
{
c1
,
err
:=
l
.
Accept
()
if
err
!=
nil
{
select
{
case
<-
closed
:
return
// closed naturally.
default
:
checkErr
(
t
,
err
)
}
}
log
(
"accepted connection"
)
sc1
,
err
:=
tr
.
NewConn
(
c1
,
true
)
checkErr
(
t
,
err
)
go
sc1
.
Serve
(
echoStream
)
}
}()
return
func
()
{
closed
<-
struct
{}{}
}
}
func
SubtestSimpleWrite
(
t
*
testing
.
T
,
tr
smux
.
Transport
)
{
l
,
err
:=
net
.
Listen
(
"tcp"
,
"localhost:0"
)
checkErr
(
t
,
err
)
log
(
"listening at %s"
,
l
.
Addr
()
.
String
())
done
:=
GoServe
(
t
,
tr
,
l
)
defer
done
()
log
(
"dialing to %s"
,
l
.
Addr
()
.
String
())
nc1
,
err
:=
net
.
Dial
(
"tcp"
,
l
.
Addr
()
.
String
())
checkErr
(
t
,
err
)
defer
nc1
.
Close
()
log
(
"wrapping conn"
)
c1
,
err
:=
tr
.
NewConn
(
nc1
,
false
)
checkErr
(
t
,
err
)
defer
c1
.
Close
()
// serve the outgoing conn, because some muxers assume
// that we _always_ call serve. (this is an error?)
go
c1
.
Serve
(
smux
.
NoOpHandler
)
log
(
"creating stream"
)
s1
,
err
:=
c1
.
OpenStream
()
checkErr
(
t
,
err
)
defer
s1
.
Close
()
buf1
:=
randBuf
(
4096
)
log
(
"writing %d bytes to stream"
,
len
(
buf1
))
_
,
err
=
s1
.
Write
(
buf1
)
checkErr
(
t
,
err
)
buf2
:=
make
([]
byte
,
len
(
buf1
))
log
(
"reading %d bytes from stream (echoed)"
,
len
(
buf2
))
_
,
err
=
s1
.
Read
(
buf2
)
checkErr
(
t
,
err
)
if
string
(
buf2
)
!=
string
(
buf1
)
{
t
.
Error
(
"buf1 and buf2 not equal: %s != %s"
,
string
(
buf1
),
string
(
buf2
))
}
log
(
"done"
)
}
func
SubtestStress
(
t
*
testing
.
T
,
opt
Options
)
{
msgsize
:=
1
<<
11
errs
:=
make
(
chan
error
,
0
)
// dont block anything.
rateLimitN
:=
5000
// max of 5k funcs, because -race has 8k max.
rateLimitChan
:=
make
(
chan
struct
{},
rateLimitN
)
for
i
:=
0
;
i
<
rateLimitN
;
i
++
{
rateLimitChan
<-
struct
{}{}
}
rateLimit
:=
func
(
f
func
())
{
<-
rateLimitChan
f
()
rateLimitChan
<-
struct
{}{}
}
writeStream
:=
func
(
s
smux
.
Stream
,
bufs
chan
<-
[]
byte
)
{
log
(
"writeStream %p, %d msgNum"
,
s
,
opt
.
msgNum
)
for
i
:=
0
;
i
<
opt
.
msgNum
;
i
++
{
buf
:=
randBuf
(
msgsize
)
bufs
<-
buf
log
(
"%p writing %d bytes (message %d/%d #%x)"
,
s
,
len
(
buf
),
i
,
opt
.
msgNum
,
buf
[
:
3
])
if
_
,
err
:=
s
.
Write
(
buf
);
err
!=
nil
{
errs
<-
fmt
.
Errorf
(
"s.Write(buf): %s"
,
err
)
continue
}
}
}
readStream
:=
func
(
s
smux
.
Stream
,
bufs
<-
chan
[]
byte
)
{
log
(
"readStream %p, %d msgNum"
,
s
,
opt
.
msgNum
)
buf2
:=
make
([]
byte
,
msgsize
)
i
:=
0
for
buf1
:=
range
bufs
{
i
++
log
(
"%p reading %d bytes (message %d/%d #%x)"
,
s
,
len
(
buf1
),
i
-
1
,
opt
.
msgNum
,
buf1
[
:
3
])
if
_
,
err
:=
io
.
ReadFull
(
s
,
buf2
);
err
!=
nil
{
errs
<-
fmt
.
Errorf
(
"io.ReadFull(s, buf2): %s"
,
err
)
log
(
"%p failed to read %d bytes (message %d/%d #%x)"
,
s
,
len
(
buf1
),
i
-
1
,
opt
.
msgNum
,
buf1
[
:
3
])
continue
}
if
!
bytes
.
Equal
(
buf1
,
buf2
)
{
errs
<-
fmt
.
Errorf
(
"buffers not equal (%x != %x)"
,
buf1
[
:
3
],
buf2
[
:
3
])
}
}
}
openStreamAndRW
:=
func
(
c
smux
.
Conn
)
{
log
(
"openStreamAndRW %p, %d opt.msgNum"
,
c
,
opt
.
msgNum
)
s
,
err
:=
c
.
OpenStream
()
if
err
!=
nil
{
errs
<-
fmt
.
Errorf
(
"Failed to create NewStream: %s"
,
err
)
return
}
bufs
:=
make
(
chan
[]
byte
,
opt
.
msgNum
)
go
func
()
{
writeStream
(
s
,
bufs
)
close
(
bufs
)
}()
readStream
(
s
,
bufs
)
s
.
Close
()
}
openConnAndRW
:=
func
()
{
log
(
"openConnAndRW"
)
l
,
err
:=
net
.
Listen
(
"tcp"
,
"localhost:0"
)
checkErr
(
t
,
err
)
done
:=
GoServe
(
t
,
opt
.
tr
,
l
)
defer
done
()
nla
:=
l
.
Addr
()
nc
,
err
:=
net
.
Dial
(
nla
.
Network
(),
nla
.
String
())
checkErr
(
t
,
err
)
if
err
!=
nil
{
t
.
Fatal
(
fmt
.
Errorf
(
"net.Dial(%s, %s): %s"
,
nla
.
Network
(),
nla
.
String
(),
err
))
return
}
c
,
err
:=
opt
.
tr
.
NewConn
(
nc
,
false
)
if
err
!=
nil
{
t
.
Fatal
(
fmt
.
Errorf
(
"a.AddConn(%s <--> %s): %s"
,
nc
.
LocalAddr
(),
nc
.
RemoteAddr
(),
err
))
return
}
// serve the outgoing conn, because some muxers assume
// that we _always_ call serve. (this is an error?)
go
c
.
Serve
(
func
(
s
smux
.
Stream
)
{
log
(
"serving connection"
)
echoStream
(
s
)
s
.
Close
()
})
var
wg
sync
.
WaitGroup
for
i
:=
0
;
i
<
opt
.
streamNum
;
i
++
{
wg
.
Add
(
1
)
go
rateLimit
(
func
()
{
defer
wg
.
Done
()
openStreamAndRW
(
c
)
})
}
wg
.
Wait
()
c
.
Close
()
}
openConnsAndRW
:=
func
()
{
log
(
"openConnsAndRW, %d conns"
,
opt
.
connNum
)
var
wg
sync
.
WaitGroup
for
i
:=
0
;
i
<
opt
.
connNum
;
i
++
{
wg
.
Add
(
1
)
go
rateLimit
(
func
()
{
defer
wg
.
Done
()
openConnAndRW
()
})
}
wg
.
Wait
()
}
go
func
()
{
openConnsAndRW
()
close
(
errs
)
// done
}()
for
err
:=
range
errs
{
t
.
Error
(
err
)
}
}
func
SubtestStress1Conn1Stream1Msg
(
t
*
testing
.
T
,
tr
smux
.
Transport
)
{
SubtestStress
(
t
,
Options
{
tr
:
tr
,
connNum
:
1
,
streamNum
:
1
,
msgNum
:
1
,
msgMax
:
100
,
msgMin
:
100
,
})
}
func
SubtestStress1Conn1Stream100Msg
(
t
*
testing
.
T
,
tr
smux
.
Transport
)
{
SubtestStress
(
t
,
Options
{
tr
:
tr
,
connNum
:
1
,
streamNum
:
1
,
msgNum
:
100
,
msgMax
:
100
,
msgMin
:
100
,
})
}
func
SubtestStress1Conn100Stream100Msg
(
t
*
testing
.
T
,
tr
smux
.
Transport
)
{
SubtestStress
(
t
,
Options
{
tr
:
tr
,
connNum
:
1
,
streamNum
:
100
,
msgNum
:
100
,
msgMax
:
100
,
msgMin
:
100
,
})
}
func
SubtestStress50Conn10Stream50Msg
(
t
*
testing
.
T
,
tr
smux
.
Transport
)
{
SubtestStress
(
t
,
Options
{
tr
:
tr
,
connNum
:
50
,
streamNum
:
10
,
msgNum
:
50
,
msgMax
:
100
,
msgMin
:
100
,
})
}
func
SubtestStress1Conn1000Stream10Msg
(
t
*
testing
.
T
,
tr
smux
.
Transport
)
{
SubtestStress
(
t
,
Options
{
tr
:
tr
,
connNum
:
1
,
streamNum
:
1000
,
msgNum
:
10
,
msgMax
:
100
,
msgMin
:
100
,
})
}
func
SubtestStress1Conn100Stream100Msg10MB
(
t
*
testing
.
T
,
tr
smux
.
Transport
)
{
SubtestStress
(
t
,
Options
{
tr
:
tr
,
connNum
:
1
,
streamNum
:
100
,
msgNum
:
100
,
msgMax
:
10000
,
msgMin
:
1000
,
})
}
func
SubtestAll
(
t
*
testing
.
T
,
tr
smux
.
Transport
)
{
tests
:=
[]
TransportTest
{
SubtestSimpleWrite
,
SubtestStress1Conn1Stream1Msg
,
SubtestStress1Conn1Stream100Msg
,
SubtestStress1Conn100Stream100Msg
,
SubtestStress50Conn10Stream50Msg
,
SubtestStress1Conn1000Stream10Msg
,
SubtestStress1Conn100Stream100Msg10MB
,
}
for
_
,
f
:=
range
tests
{
if
testing
.
Verbose
()
{
fmt
.
Fprintf
(
os
.
Stderr
,
"==== RUN %s
\n
"
,
GetFunctionName
(
f
))
}
f
(
t
,
tr
)
}
}
type
TransportTest
func
(
t
*
testing
.
T
,
tr
smux
.
Transport
)
func
TestNoOp
(
t
*
testing
.
T
)
{}
func
GetFunctionName
(
i
interface
{})
string
{
return
runtime
.
FuncForPC
(
reflect
.
ValueOf
(
i
)
.
Pointer
())
.
Name
()
}
vendor/gx/QmRmT6MSnfhRDW1PTUGSd3z4fqXK48GUequQAZzeT4c5iC/go-stream-muxer/yamux/yamux.go
deleted
100644 → 0
View file @
a40ef343
package
sm_yamux
import
(
"io/ioutil"
"net"
"time"
smux
"gx/QmRmT6MSnfhRDW1PTUGSd3z4fqXK48GUequQAZzeT4c5iC/go-stream-muxer"
yamux
"gx/QmT98GixWnJUj3vHfoURNQa5uk8FxxmZVF5nv3AicXp2R1/yamux"
)
// stream implements smux.Stream using a ss.Stream
type
stream
yamux
.
Stream
func
(
s
*
stream
)
yamuxStream
()
*
yamux
.
Stream
{
return
(
*
yamux
.
Stream
)(
s
)
}
func
(
s
*
stream
)
Read
(
buf
[]
byte
)
(
int
,
error
)
{
return
s
.
yamuxStream
()
.
Read
(
buf
)
}
func
(
s
*
stream
)
Write
(
buf
[]
byte
)
(
int
,
error
)
{
return
s
.
yamuxStream
()
.
Write
(
buf
)
}
func
(
s
*
stream
)
Close
()
error
{
return
s
.
yamuxStream
()
.
Close
()
}
// Conn is a connection to a remote peer.
type
conn
yamux
.
Session
func
(
c
*
conn
)
yamuxSession
()
*
yamux
.
Session
{
return
(
*
yamux
.
Session
)(
c
)
}
func
(
c
*
conn
)
Close
()
error
{
return
c
.
yamuxSession
()
.
Close
()
}
func
(
c
*
conn
)
IsClosed
()
bool
{
return
c
.
yamuxSession
()
.
IsClosed
()
}
// OpenStream creates a new stream.
func
(
c
*
conn
)
OpenStream
()
(
smux
.
Stream
,
error
)
{
s
,
err
:=
c
.
yamuxSession
()
.
OpenStream
()
if
err
!=
nil
{
return
nil
,
err
}
return
(
*
stream
)(
s
),
nil
}
// AcceptStream accepts a stream opened by the other side.
func
(
c
*
conn
)
AcceptStream
()
(
smux
.
Stream
,
error
)
{
s
,
err
:=
c
.
yamuxSession
()
.
AcceptStream
()
return
(
*
stream
)(
s
),
err
}
// Serve starts listening for incoming requests and handles them
// using given StreamHandler
func
(
c
*
conn
)
Serve
(
handler
smux
.
StreamHandler
)
{
for
{
// accept loop
s
,
err
:=
c
.
AcceptStream
()
if
err
!=
nil
{
return
// err always means closed.
}
go
handler
(
s
)
}
}
// Transport is a go-peerstream transport that constructs
// yamux-backed connections.
type
Transport
yamux
.
Config
// DefaultTransport has default settings for yamux
var
DefaultTransport
=
(
*
Transport
)(
&
yamux
.
Config
{
AcceptBacklog
:
256
,
// from yamux.DefaultConfig
EnableKeepAlive
:
true
,
// from yamux.DefaultConfig
KeepAliveInterval
:
30
*
time
.
Second
,
// from yamux.DefaultConfig
MaxStreamWindowSize
:
uint32
(
256
*
1024
),
// from yamux.DefaultConfig
LogOutput
:
ioutil
.
Discard
,
})
func
(
t
*
Transport
)
NewConn
(
nc
net
.
Conn
,
isServer
bool
)
(
smux
.
Conn
,
error
)
{
var
s
*
yamux
.
Session
var
err
error
if
isServer
{
s
,
err
=
yamux
.
Server
(
nc
,
t
.
Config
())
}
else
{
s
,
err
=
yamux
.
Client
(
nc
,
t
.
Config
())
}
return
(
*
conn
)(
s
),
err
}
func
(
t
*
Transport
)
Config
()
*
yamux
.
Config
{
return
(
*
yamux
.
Config
)(
t
)
}
vendor/gx/QmRmT6MSnfhRDW1PTUGSd3z4fqXK48GUequQAZzeT4c5iC/go-stream-muxer/yamux/yamux_test.go
deleted
100644 → 0
View file @
a40ef343
package
sm_yamux
import
(
"testing"
test
"gx/QmRmT6MSnfhRDW1PTUGSd3z4fqXK48GUequQAZzeT4c5iC/go-stream-muxer/test"
)
func
TestYamuxTransport
(
t
*
testing
.
T
)
{
test
.
SubtestAll
(
t
,
DefaultTransport
)
}
vendor/gx/QmSQRViqskLPYFbjKhWE5EaW8eou9SD2j52QaBkQdigMsG/crypto-sha3/doc.go
deleted
100644 → 0
View file @
a40ef343
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package sha3 implements the SHA-3 fixed-output-length hash functions and
// the SHAKE variable-output-length hash functions defined by FIPS-202.
//
// Both types of hash function use the "sponge" construction and the Keccak
// permutation. For a detailed specification see http://keccak.noekeon.org/
//
//
// Guidance
//
// If you aren't sure what function you need, use SHAKE256 with at least 64
// bytes of output. The SHAKE instances are faster than the SHA3 instances;
// the latter have to allocate memory to conform to the hash.Hash interface.
//
// If you need a secret-key MAC (message authentication code), prepend the
// secret key to the input, hash with SHAKE256 and read at least 32 bytes of
// output.
//
//
// Security strengths
//
// The SHA3-x (x equals 224, 256, 384, or 512) functions have a security
// strength against preimage attacks of x bits. Since they only produce "x"
// bits of output, their collision-resistance is only "x/2" bits.
//
// The SHAKE-256 and -128 functions have a generic security strength of 256 and
// 128 bits against all attacks, provided that at least 2x bits of their output
// is used. Requesting more than 64 or 32 bytes of output, respectively, does
// not increase the collision-resistance of the SHAKE functions.
//
//
// The sponge construction
//
// A sponge builds a pseudo-random function from a public pseudo-random
// permutation, by applying the permutation to a state of "rate + capacity"
// bytes, but hiding "capacity" of the bytes.
//
// A sponge starts out with a zero state. To hash an input using a sponge, up
// to "rate" bytes of the input are XORed into the sponge's state. The sponge
// is then "full" and the permutation is applied to "empty" it. This process is
// repeated until all the input has been "absorbed". The input is then padded.
// The digest is "squeezed" from the sponge in the same way, except that output
// output is copied out instead of input being XORed in.
//
// A sponge is parameterized by its generic security strength, which is equal
// to half its capacity; capacity + rate is equal to the permutation's width.
// Since the KeccakF-1600 permutation is 1600 bits (200 bytes) wide, this means
// that the security strength of a sponge instance is equal to (1600 - bitrate) / 2.
//
//
// Recommendations
//
// The SHAKE functions are recommended for most new uses. They can produce
// output of arbitrary length. SHAKE256, with an output length of at least
// 64 bytes, provides 256-bit security against all attacks. The Keccak team
// recommends it for most applications upgrading from SHA2-512. (NIST chose a
// much stronger, but much slower, sponge instance for SHA3-512.)
//
// The SHA-3 functions are "drop-in" replacements for the SHA-2 functions.
// They produce output of the same length, with the same security strengths
// against all attacks. This means, in particular, that SHA3-256 only has
// 128-bit collision resistance, because its output length is 32 bytes.
package
sha3
vendor/gx/QmSQRViqskLPYFbjKhWE5EaW8eou9SD2j52QaBkQdigMsG/crypto-sha3/hashes.go
deleted
100644 → 0
View file @
a40ef343
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
sha3
// This file provides functions for creating instances of the SHA-3
// and SHAKE hash functions, as well as utility functions for hashing
// bytes.
import
(
"hash"
)
// New224 creates a new SHA3-224 hash.
// Its generic security strength is 224 bits against preimage attacks,
// and 112 bits against collision attacks.
func
New224
()
hash
.
Hash
{
return
&
state
{
rate
:
144
,
outputLen
:
28
,
dsbyte
:
0x06
}
}
// New256 creates a new SHA3-256 hash.
// Its generic security strength is 256 bits against preimage attacks,
// and 128 bits against collision attacks.
func
New256
()
hash
.
Hash
{
return
&
state
{
rate
:
136
,
outputLen
:
32
,
dsbyte
:
0x06
}
}
// New384 creates a new SHA3-384 hash.
// Its generic security strength is 384 bits against preimage attacks,
// and 192 bits against collision attacks.
func
New384
()
hash
.
Hash
{
return
&
state
{
rate
:
104
,
outputLen
:
48
,
dsbyte
:
0x06
}
}
// New512 creates a new SHA3-512 hash.
// Its generic security strength is 512 bits against preimage attacks,
// and 256 bits against collision attacks.
func
New512
()
hash
.
Hash
{
return
&
state
{
rate
:
72
,
outputLen
:
64
,
dsbyte
:
0x06
}
}
// Sum224 returns the SHA3-224 digest of the data.
func
Sum224
(
data
[]
byte
)
(
digest
[
28
]
byte
)
{
h
:=
New224
()
h
.
Write
(
data
)
h
.
Sum
(
digest
[
:
0
])
return
}
// Sum256 returns the SHA3-256 digest of the data.
func
Sum256
(
data
[]
byte
)
(
digest
[
32
]
byte
)
{
h
:=
New256
()
h
.
Write
(
data
)
h
.
Sum
(
digest
[
:
0
])
return
}
// Sum384 returns the SHA3-384 digest of the data.
func
Sum384
(
data
[]
byte
)
(
digest
[
48
]
byte
)
{
h
:=
New384
()
h
.
Write
(
data
)
h
.
Sum
(
digest
[
:
0
])
return
}
// Sum512 returns the SHA3-512 digest of the data.
func
Sum512
(
data
[]
byte
)
(
digest
[
64
]
byte
)
{
h
:=
New512
()
h
.
Write
(
data
)
h
.
Sum
(
digest
[
:
0
])
return
}
vendor/gx/QmSQRViqskLPYFbjKhWE5EaW8eou9SD2j52QaBkQdigMsG/crypto-sha3/keccakf.go
deleted
100644 → 0
View file @
a40ef343
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
sha3
// rc stores the round constants for use in the ι step.
var
rc
=
[
24
]
uint64
{
0x0000000000000001
,
0x0000000000008082
,
0x800000000000808A
,
0x8000000080008000
,
0x000000000000808B
,
0x0000000080000001
,
0x8000000080008081
,
0x8000000000008009
,
0x000000000000008A
,
0x0000000000000088
,
0x0000000080008009
,
0x000000008000000A
,
0x000000008000808B
,
0x800000000000008B
,
0x8000000000008089
,
0x8000000000008003
,
0x8000000000008002
,
0x8000000000000080
,
0x000000000000800A
,
0x800000008000000A
,
0x8000000080008081
,
0x8000000000008080
,
0x0000000080000001
,
0x8000000080008008
,
}
// keccakF1600 applies the Keccak permutation to a 1600b-wide
// state represented as a slice of 25 uint64s.
func
keccakF1600
(
a
*
[
25
]
uint64
)
{
// Implementation translated from Keccak-inplace.c
// in the keccak reference code.
var
t
,
bc0
,
bc1
,
bc2
,
bc3
,
bc4
,
d0
,
d1
,
d2
,
d3
,
d4
uint64
for
i
:=
0
;
i
<
24
;
i
+=
4
{
// Combines the 5 steps in each round into 2 steps.
// Unrolls 4 rounds per loop and spreads some steps across rounds.
// Round 1
bc0
=
a
[
0
]
^
a
[
5
]
^
a
[
10
]
^
a
[
15
]
^
a
[
20
]
bc1
=
a
[
1
]
^
a
[
6
]
^
a
[
11
]
^
a
[
16
]
^
a
[
21
]
bc2
=
a
[
2
]
^
a
[
7
]
^
a
[
12
]
^
a
[
17
]
^
a
[
22
]
bc3
=
a
[
3
]
^
a
[
8
]
^
a
[
13
]
^
a
[
18
]
^
a
[
23
]
bc4
=
a
[
4
]
^
a
[
9
]
^
a
[
14
]
^
a
[
19
]
^
a
[
24
]
d0
=
bc4
^
(
bc1
<<
1
|
bc1
>>
63
)
d1
=
bc0
^
(
bc2
<<
1
|
bc2
>>
63
)
d2
=
bc1
^
(
bc3
<<
1
|
bc3
>>
63
)
d3
=
bc2
^
(
bc4
<<
1
|
bc4
>>
63
)
d4
=
bc3
^
(
bc0
<<
1
|
bc0
>>
63
)
bc0
=
a
[
0
]
^
d0
t
=
a
[
6
]
^
d1
bc1
=
t
<<
44
|
t
>>
(
64
-
44
)
t
=
a
[
12
]
^
d2
bc2
=
t
<<
43
|
t
>>
(
64
-
43
)
t
=
a
[
18
]
^
d3
bc3
=
t
<<
21
|
t
>>
(
64
-
21
)
t
=
a
[
24
]
^
d4
bc4
=
t
<<
14
|
t
>>
(
64
-
14
)
a
[
0
]
=
bc0
^
(
bc2
&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
^
d2
bc3
=
t
<<
15
|
t
>>
(
64
-
15
)
t
=
a
[
18
]
^
d3
bc4
=
t
<<
56
|
t
>>
(
64
-
56
)
t
=
a
[
19
]
^
d4
bc0
=
t
<<
27
|
t
>>
(
64
-
27
)
a
[
15
]
=
bc0
^
(
bc2
&^
bc1
)
a
[
16
]
=
bc1
^
(
bc3
&^
bc2
)
a
[
17
]
=
bc2
^
(
bc4
&^
bc3
)
a
[
18
]
=
bc3
^
(
bc0
&^
bc4
)
a
[
19
]
=
bc4
^
(
bc1
&^
bc0
)
t
=
a
[
20
]
^
d0
bc3
=
t
<<
41
|
t
>>
(
64
-
41
)
t
=
a
[
21
]
^
d1
bc4
=
t
<<
2
|
t
>>
(
64
-
2
)
t
=
a
[
22
]
^
d2
bc0
=
t
<<
62
|
t
>>
(
64
-
62
)
t
=
a
[
23
]
^
d3
bc1
=
t
<<
55
|
t
>>
(
64
-
55
)
t
=
a
[
24
]
^
d4
bc2
=
t
<<
39
|
t
>>
(
64
-
39
)
a
[
20
]
=
bc0
^
(
bc2
&^
bc1
)
a
[
21
]
=
bc1
^
(
bc3
&^
bc2
)
a
[
22
]
=
bc2
^
(
bc4
&^
bc3
)
a
[
23
]
=
bc3
^
(
bc0
&^
bc4
)
a
[
24
]
=
bc4
^
(
bc1
&^
bc0
)
}
}
vendor/gx/QmSQRViqskLPYFbjKhWE5EaW8eou9SD2j52QaBkQdigMsG/crypto-sha3/package.json
deleted
100644 → 0
View file @
a40ef343
{
"name"
:
"crypto-sha3"
,
"author"
:
"whyrusleeping"
,
"version"
:
"1.0.0"
,
"language"
:
"go"
,
"gx"
:
{
"dvcsimport"
:
"golang.org/x/crypto/sha3"
}
}
\ No newline at end of file
vendor/gx/QmSQRViqskLPYFbjKhWE5EaW8eou9SD2j52QaBkQdigMsG/crypto-sha3/register.go
deleted
100644 → 0
View file @
a40ef343
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build go1.4
package
sha3
import
(
"crypto"
)
func
init
()
{
crypto
.
RegisterHash
(
crypto
.
SHA3_224
,
New224
)
crypto
.
RegisterHash
(
crypto
.
SHA3_256
,
New256
)
crypto
.
RegisterHash
(
crypto
.
SHA3_384
,
New384
)
crypto
.
RegisterHash
(
crypto
.
SHA3_512
,
New512
)
}
vendor/gx/QmSQRViqskLPYFbjKhWE5EaW8eou9SD2j52QaBkQdigMsG/crypto-sha3/sha3.go
deleted
100644 → 0
View file @
a40ef343
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
sha3
// spongeDirection indicates the direction bytes are flowing through the sponge.
type
spongeDirection
int
const
(
// spongeAbsorbing indicates that the sponge is absorbing input.
spongeAbsorbing
spongeDirection
=
iota
// spongeSqueezing indicates that the sponge is being squeezed.
spongeSqueezing
)
const
(
// maxRate is the maximum size of the internal buffer. SHAKE-256
// currently needs the largest buffer.
maxRate
=
168
)
type
state
struct
{
// Generic sponge components.
a
[
25
]
uint64
// main state of the hash
buf
[]
byte
// points into storage
rate
int
// the number of bytes of state to use
// dsbyte contains the "domain separation" bits and the first bit of
// the padding. Sections 6.1 and 6.2 of [1] separate the outputs of the
// SHA-3 and SHAKE functions by appending bitstrings to the message.
// Using a little-endian bit-ordering convention, these are "01" for SHA-3
// and "1111" for SHAKE, or 00000010b and 00001111b, respectively. Then the
// padding rule from section 5.1 is applied to pad the message to a multiple
// of the rate, which involves adding a "1" bit, zero or more "0" bits, and
// a final "1" bit. We merge the first "1" bit from the padding into dsbyte,
// giving 00000110b (0x06) and 00011111b (0x1f).
// [1] http://csrc.nist.gov/publications/drafts/fips-202/fips_202_draft.pdf
// "Draft FIPS 202: SHA-3 Standard: Permutation-Based Hash and
// Extendable-Output Functions (May 2014)"
dsbyte
byte
storage
[
maxRate
]
byte
// Specific to SHA-3 and SHAKE.
fixedOutput
bool
// whether this is a fixed-ouput-length instance
outputLen
int
// the default output size in bytes
state
spongeDirection
// whether the sponge is absorbing or squeezing
}
// BlockSize returns the rate of sponge underlying this hash function.
func
(
d
*
state
)
BlockSize
()
int
{
return
d
.
rate
}
// Size returns the output size of the hash function in bytes.
func
(
d
*
state
)
Size
()
int
{
return
d
.
outputLen
}
// Reset clears the internal state by zeroing the sponge state and
// the byte buffer, and setting Sponge.state to absorbing.
func
(
d
*
state
)
Reset
()
{
// Zero the permutation's state.
for
i
:=
range
d
.
a
{
d
.
a
[
i
]
=
0
}
d
.
state
=
spongeAbsorbing
d
.
buf
=
d
.
storage
[
:
0
]
}
func
(
d
*
state
)
clone
()
*
state
{
ret
:=
*
d
if
ret
.
state
==
spongeAbsorbing
{
ret
.
buf
=
ret
.
storage
[
:
len
(
ret
.
buf
)]
}
else
{
ret
.
buf
=
ret
.
storage
[
d
.
rate
-
cap
(
d
.
buf
)
:
d
.
rate
]
}
return
&
ret
}
// permute applies the KeccakF-1600 permutation. It handles
// any input-output buffering.
func
(
d
*
state
)
permute
()
{
switch
d
.
state
{
case
spongeAbsorbing
:
// If we're absorbing, we need to xor the input into the state
// before applying the permutation.
xorIn
(
d
,
d
.
buf
)
d
.
buf
=
d
.
storage
[
:
0
]
keccakF1600
(
&
d
.
a
)
case
spongeSqueezing
:
// If we're squeezing, we need to apply the permutatin before
// copying more output.
keccakF1600
(
&
d
.
a
)
d
.
buf
=
d
.
storage
[
:
d
.
rate
]
copyOut
(
d
,
d
.
buf
)
}
}
// pads appends the domain separation bits in dsbyte, applies
// the multi-bitrate 10..1 padding rule, and permutes the state.
func
(
d
*
state
)
padAndPermute
(
dsbyte
byte
)
{
if
d
.
buf
==
nil
{
d
.
buf
=
d
.
storage
[
:
0
]
}
// Pad with this instance's domain-separator bits. We know that there's
// at least one byte of space in d.buf because, if it were full,
// permute would have been called to empty it. dsbyte also contains the
// first one bit for the padding. See the comment in the state struct.
d
.
buf
=
append
(
d
.
buf
,
dsbyte
)
zerosStart
:=
len
(
d
.
buf
)
d
.
buf
=
d
.
storage
[
:
d
.
rate
]
for
i
:=
zerosStart
;
i
<
d
.
rate
;
i
++
{
d
.
buf
[
i
]
=
0
}
// This adds the final one bit for the padding. Because of the way that
// bits are numbered from the LSB upwards, the final bit is the MSB of
// the last byte.
d
.
buf
[
d
.
rate
-
1
]
^=
0x80
// Apply the permutation
d
.
permute
()
d
.
state
=
spongeSqueezing
d
.
buf
=
d
.
storage
[
:
d
.
rate
]
copyOut
(
d
,
d
.
buf
)
}
// Write absorbs more data into the hash's state. It produces an error
// if more data is written to the ShakeHash after writing
func
(
d
*
state
)
Write
(
p
[]
byte
)
(
written
int
,
err
error
)
{
if
d
.
state
!=
spongeAbsorbing
{
panic
(
"sha3: write to sponge after read"
)
}
if
d
.
buf
==
nil
{
d
.
buf
=
d
.
storage
[
:
0
]
}
written
=
len
(
p
)
for
len
(
p
)
>
0
{
if
len
(
d
.
buf
)
==
0
&&
len
(
p
)
>=
d
.
rate
{
// The fast path; absorb a full "rate" bytes of input and apply the permutation.
xorIn
(
d
,
p
[
:
d
.
rate
])
p
=
p
[
d
.
rate
:
]
keccakF1600
(
&
d
.
a
)
}
else
{
// The slow path; buffer the input until we can fill the sponge, and then xor it in.
todo
:=
d
.
rate
-
len
(
d
.
buf
)
if
todo
>
len
(
p
)
{
todo
=
len
(
p
)
}
d
.
buf
=
append
(
d
.
buf
,
p
[
:
todo
]
...
)
p
=
p
[
todo
:
]
// If the sponge is full, apply the permutation.
if
len
(
d
.
buf
)
==
d
.
rate
{
d
.
permute
()
}
}
}
return
}
// Read squeezes an arbitrary number of bytes from the sponge.
func
(
d
*
state
)
Read
(
out
[]
byte
)
(
n
int
,
err
error
)
{
// If we're still absorbing, pad and apply the permutation.
if
d
.
state
==
spongeAbsorbing
{
d
.
padAndPermute
(
d
.
dsbyte
)
}
n
=
len
(
out
)
// Now, do the squeezing.
for
len
(
out
)
>
0
{
n
:=
copy
(
out
,
d
.
buf
)
d
.
buf
=
d
.
buf
[
n
:
]
out
=
out
[
n
:
]
// Apply the permutation if we've squeezed the sponge dry.
if
len
(
d
.
buf
)
==
0
{
d
.
permute
()
}
}
return
}
// Sum applies padding to the hash state and then squeezes out the desired
// number of output bytes.
func
(
d
*
state
)
Sum
(
in
[]
byte
)
[]
byte
{
// Make a copy of the original hash so that caller can keep writing
// and summing.
dup
:=
d
.
clone
()
hash
:=
make
([]
byte
,
dup
.
outputLen
)
dup
.
Read
(
hash
)
return
append
(
in
,
hash
...
)
}
vendor/gx/QmSQRViqskLPYFbjKhWE5EaW8eou9SD2j52QaBkQdigMsG/crypto-sha3/sha3_test.go
deleted
100644 → 0
View file @
a40ef343
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
sha3
// Tests include all the ShortMsgKATs provided by the Keccak team at
// https://github.com/gvanas/KeccakCodePackage
//
// They only include the zero-bit case of the bitwise testvectors
// published by NIST in the draft of FIPS-202.
import
(
"bytes"
"compress/flate"
"encoding/hex"
"encoding/json"
"hash"
"os"
"strings"
"testing"
)
const
(
testString
=
"brekeccakkeccak koax koax"
katFilename
=
"testdata/keccakKats.json.deflate"
)
// Internal-use instances of SHAKE used to test against KATs.
func
newHashShake128
()
hash
.
Hash
{
return
&
state
{
rate
:
168
,
dsbyte
:
0x1f
,
outputLen
:
512
}
}
func
newHashShake256
()
hash
.
Hash
{
return
&
state
{
rate
:
136
,
dsbyte
:
0x1f
,
outputLen
:
512
}
}
// testDigests contains functions returning hash.Hash instances
// with output-length equal to the KAT length for both SHA-3 and
// SHAKE instances.
var
testDigests
=
map
[
string
]
func
()
hash
.
Hash
{
"SHA3-224"
:
New224
,
"SHA3-256"
:
New256
,
"SHA3-384"
:
New384
,
"SHA3-512"
:
New512
,
"SHAKE128"
:
newHashShake128
,
"SHAKE256"
:
newHashShake256
,
}
// testShakes contains functions that return ShakeHash instances for
// testing the ShakeHash-specific interface.
var
testShakes
=
map
[
string
]
func
()
ShakeHash
{
"SHAKE128"
:
NewShake128
,
"SHAKE256"
:
NewShake256
,
}
// decodeHex converts a hex-encoded string into a raw byte string.
func
decodeHex
(
s
string
)
[]
byte
{
b
,
err
:=
hex
.
DecodeString
(
s
)
if
err
!=
nil
{
panic
(
err
)
}
return
b
}
// structs used to marshal JSON test-cases.
type
KeccakKats
struct
{
Kats
map
[
string
][]
struct
{
Digest
string
`json:"digest"`
Length
int64
`json:"length"`
Message
string
`json:"message"`
}
}
func
testUnalignedAndGeneric
(
t
*
testing
.
T
,
testf
func
(
impl
string
))
{
xorInOrig
,
copyOutOrig
:=
xorIn
,
copyOut
xorIn
,
copyOut
=
xorInGeneric
,
copyOutGeneric
testf
(
"generic"
)
if
xorImplementationUnaligned
!=
"generic"
{
xorIn
,
copyOut
=
xorInUnaligned
,
copyOutUnaligned
testf
(
"unaligned"
)
}
xorIn
,
copyOut
=
xorInOrig
,
copyOutOrig
}
// TestKeccakKats tests the SHA-3 and Shake implementations against all the
// ShortMsgKATs from https://github.com/gvanas/KeccakCodePackage
// (The testvectors are stored in keccakKats.json.deflate due to their length.)
func
TestKeccakKats
(
t
*
testing
.
T
)
{
testUnalignedAndGeneric
(
t
,
func
(
impl
string
)
{
// Read the KATs.
deflated
,
err
:=
os
.
Open
(
katFilename
)
if
err
!=
nil
{
t
.
Errorf
(
"error opening %s: %s"
,
katFilename
,
err
)
}
file
:=
flate
.
NewReader
(
deflated
)
dec
:=
json
.
NewDecoder
(
file
)
var
katSet
KeccakKats
err
=
dec
.
Decode
(
&
katSet
)
if
err
!=
nil
{
t
.
Errorf
(
"error decoding KATs: %s"
,
err
)
}
// Do the KATs.
for
functionName
,
kats
:=
range
katSet
.
Kats
{
d
:=
testDigests
[
functionName
]()
for
_
,
kat
:=
range
kats
{
d
.
Reset
()
in
,
err
:=
hex
.
DecodeString
(
kat
.
Message
)
if
err
!=
nil
{
t
.
Errorf
(
"error decoding KAT: %s"
,
err
)
}
d
.
Write
(
in
[
:
kat
.
Length
/
8
])
got
:=
strings
.
ToUpper
(
hex
.
EncodeToString
(
d
.
Sum
(
nil
)))
if
got
!=
kat
.
Digest
{
t
.
Errorf
(
"function=%s, implementation=%s, length=%d
\n
message:
\n
%s
\n
got:
\n
%s
\n
wanted:
\n
%s"
,
functionName
,
impl
,
kat
.
Length
,
kat
.
Message
,
got
,
kat
.
Digest
)
t
.
Logf
(
"wanted %+v"
,
kat
)
t
.
FailNow
()
}
continue
}
}
})
}
// TestUnalignedWrite tests that writing data in an arbitrary pattern with
// small input buffers.
func
testUnalignedWrite
(
t
*
testing
.
T
)
{
testUnalignedAndGeneric
(
t
,
func
(
impl
string
)
{
buf
:=
sequentialBytes
(
0x10000
)
for
alg
,
df
:=
range
testDigests
{
d
:=
df
()
d
.
Reset
()
d
.
Write
(
buf
)
want
:=
d
.
Sum
(
nil
)
d
.
Reset
()
for
i
:=
0
;
i
<
len
(
buf
);
{
// Cycle through offsets which make a 137 byte sequence.
// Because 137 is prime this sequence should exercise all corner cases.
offsets
:=
[
17
]
int
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
1
}
for
_
,
j
:=
range
offsets
{
if
v
:=
len
(
buf
)
-
i
;
v
<
j
{
j
=
v
}
d
.
Write
(
buf
[
i
:
i
+
j
])
i
+=
j
}
}
got
:=
d
.
Sum
(
nil
)
if
!
bytes
.
Equal
(
got
,
want
)
{
t
.
Errorf
(
"Unaligned writes, implementation=%s, alg=%s
\n
got %q, want %q"
,
impl
,
alg
,
got
,
want
)
}
}
})
}
// TestAppend checks that appending works when reallocation is necessary.
func
TestAppend
(
t
*
testing
.
T
)
{
testUnalignedAndGeneric
(
t
,
func
(
impl
string
)
{
d
:=
New224
()
for
capacity
:=
2
;
capacity
<=
66
;
capacity
+=
64
{
// The first time around the loop, Sum will have to reallocate.
// The second time, it will not.
buf
:=
make
([]
byte
,
2
,
capacity
)
d
.
Reset
()
d
.
Write
([]
byte
{
0xcc
})
buf
=
d
.
Sum
(
buf
)
expected
:=
"0000DF70ADC49B2E76EEE3A6931B93FA41841C3AF2CDF5B32A18B5478C39"
if
got
:=
strings
.
ToUpper
(
hex
.
EncodeToString
(
buf
));
got
!=
expected
{
t
.
Errorf
(
"got %s, want %s"
,
got
,
expected
)
}
}
})
}
// TestAppendNoRealloc tests that appending works when no reallocation is necessary.
func
TestAppendNoRealloc
(
t
*
testing
.
T
)
{
testUnalignedAndGeneric
(
t
,
func
(
impl
string
)
{
buf
:=
make
([]
byte
,
1
,
200
)
d
:=
New224
()
d
.
Write
([]
byte
{
0xcc
})
buf
=
d
.
Sum
(
buf
)
expected
:=
"00DF70ADC49B2E76EEE3A6931B93FA41841C3AF2CDF5B32A18B5478C39"
if
got
:=
strings
.
ToUpper
(
hex
.
EncodeToString
(
buf
));
got
!=
expected
{
t
.
Errorf
(
"%s: got %s, want %s"
,
impl
,
got
,
expected
)
}
})
}
// TestSqueezing checks that squeezing the full output a single time produces
// the same output as repeatedly squeezing the instance.
func
TestSqueezing
(
t
*
testing
.
T
)
{
testUnalignedAndGeneric
(
t
,
func
(
impl
string
)
{
for
functionName
,
newShakeHash
:=
range
testShakes
{
d0
:=
newShakeHash
()
d0
.
Write
([]
byte
(
testString
))
ref
:=
make
([]
byte
,
32
)
d0
.
Read
(
ref
)
d1
:=
newShakeHash
()
d1
.
Write
([]
byte
(
testString
))
var
multiple
[]
byte
for
_
=
range
ref
{
one
:=
make
([]
byte
,
1
)
d1
.
Read
(
one
)
multiple
=
append
(
multiple
,
one
...
)
}
if
!
bytes
.
Equal
(
ref
,
multiple
)
{
t
.
Errorf
(
"%s (%s): squeezing %d bytes one at a time failed"
,
functionName
,
impl
,
len
(
ref
))
}
}
})
}
// sequentialBytes produces a buffer of size consecutive bytes 0x00, 0x01, ..., used for testing.
func
sequentialBytes
(
size
int
)
[]
byte
{
result
:=
make
([]
byte
,
size
)
for
i
:=
range
result
{
result
[
i
]
=
byte
(
i
)
}
return
result
}
// BenchmarkPermutationFunction measures the speed of the permutation function
// with no input data.
func
BenchmarkPermutationFunction
(
b
*
testing
.
B
)
{
b
.
SetBytes
(
int64
(
200
))
var
lanes
[
25
]
uint64
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
keccakF1600
(
&
lanes
)
}
}
// benchmarkHash tests the speed to hash num buffers of buflen each.
func
benchmarkHash
(
b
*
testing
.
B
,
h
hash
.
Hash
,
size
,
num
int
)
{
b
.
StopTimer
()
h
.
Reset
()
data
:=
sequentialBytes
(
size
)
b
.
SetBytes
(
int64
(
size
*
num
))
b
.
StartTimer
()
var
state
[]
byte
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
for
j
:=
0
;
j
<
num
;
j
++
{
h
.
Write
(
data
)
}
state
=
h
.
Sum
(
state
[
:
0
])
}
b
.
StopTimer
()
h
.
Reset
()
}
// benchmarkShake is specialized to the Shake instances, which don't
// require a copy on reading output.
func
benchmarkShake
(
b
*
testing
.
B
,
h
ShakeHash
,
size
,
num
int
)
{
b
.
StopTimer
()
h
.
Reset
()
data
:=
sequentialBytes
(
size
)
d
:=
make
([]
byte
,
32
)
b
.
SetBytes
(
int64
(
size
*
num
))
b
.
StartTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
h
.
Reset
()
for
j
:=
0
;
j
<
num
;
j
++
{
h
.
Write
(
data
)
}
h
.
Read
(
d
)
}
}
func
BenchmarkSha3_512_MTU
(
b
*
testing
.
B
)
{
benchmarkHash
(
b
,
New512
(),
1350
,
1
)
}
func
BenchmarkSha3_384_MTU
(
b
*
testing
.
B
)
{
benchmarkHash
(
b
,
New384
(),
1350
,
1
)
}
func
BenchmarkSha3_256_MTU
(
b
*
testing
.
B
)
{
benchmarkHash
(
b
,
New256
(),
1350
,
1
)
}
func
BenchmarkSha3_224_MTU
(
b
*
testing
.
B
)
{
benchmarkHash
(
b
,
New224
(),
1350
,
1
)
}
func
BenchmarkShake128_MTU
(
b
*
testing
.
B
)
{
benchmarkShake
(
b
,
NewShake128
(),
1350
,
1
)
}
func
BenchmarkShake256_MTU
(
b
*
testing
.
B
)
{
benchmarkShake
(
b
,
NewShake256
(),
1350
,
1
)
}
func
BenchmarkShake256_16x
(
b
*
testing
.
B
)
{
benchmarkShake
(
b
,
NewShake256
(),
16
,
1024
)
}
func
BenchmarkShake256_1MiB
(
b
*
testing
.
B
)
{
benchmarkShake
(
b
,
NewShake256
(),
1024
,
1024
)
}
func
BenchmarkSha3_512_1MiB
(
b
*
testing
.
B
)
{
benchmarkHash
(
b
,
New512
(),
1024
,
1024
)
}
func
Example_sum
()
{
buf
:=
[]
byte
(
"some data to hash"
)
// A hash needs to be 64 bytes long to have 256-bit collision resistance.
h
:=
make
([]
byte
,
64
)
// Compute a 64-byte hash of buf and put it in h.
ShakeSum256
(
h
,
buf
)
}
func
Example_mac
()
{
k
:=
[]
byte
(
"this is a secret key; you should generate a strong random key that's at least 32 bytes long"
)
buf
:=
[]
byte
(
"and this is some data to authenticate"
)
// A MAC with 32 bytes of output has 256-bit security strength -- if you use at least a 32-byte-long key.
h
:=
make
([]
byte
,
32
)
d
:=
NewShake256
()
// Write the key into the hash.
d
.
Write
(
k
)
// Now write the data.
d
.
Write
(
buf
)
// Read 32 bytes of output from the hash into h.
d
.
Read
(
h
)
}
vendor/gx/QmSQRViqskLPYFbjKhWE5EaW8eou9SD2j52QaBkQdigMsG/crypto-sha3/shake.go
deleted
100644 → 0
View file @
a40ef343
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
sha3
// This file defines the ShakeHash interface, and provides
// functions for creating SHAKE instances, as well as utility
// functions for hashing bytes to arbitrary-length output.
import
(
"io"
)
// ShakeHash defines the interface to hash functions that
// support arbitrary-length output.
type
ShakeHash
interface
{
// Write absorbs more data into the hash's state. It panics if input is
// written to it after output has been read from it.
io
.
Writer
// Read reads more output from the hash; reading affects the hash's
// state. (ShakeHash.Read is thus very different from Hash.Sum)
// It never returns an error.
io
.
Reader
// Clone returns a copy of the ShakeHash in its current state.
Clone
()
ShakeHash
// Reset resets the ShakeHash to its initial state.
Reset
()
}
func
(
d
*
state
)
Clone
()
ShakeHash
{
return
d
.
clone
()
}
// NewShake128 creates a new SHAKE128 variable-output-length ShakeHash.
// Its generic security strength is 128 bits against all attacks if at
// least 32 bytes of its output are used.
func
NewShake128
()
ShakeHash
{
return
&
state
{
rate
:
168
,
dsbyte
:
0x1f
}
}
// NewShake256 creates a new SHAKE128 variable-output-length ShakeHash.
// Its generic security strength is 256 bits against all attacks if
// at least 64 bytes of its output are used.
func
NewShake256
()
ShakeHash
{
return
&
state
{
rate
:
136
,
dsbyte
:
0x1f
}
}
// ShakeSum128 writes an arbitrary-length digest of data into hash.
func
ShakeSum128
(
hash
,
data
[]
byte
)
{
h
:=
NewShake128
()
h
.
Write
(
data
)
h
.
Read
(
hash
)
}
// ShakeSum256 writes an arbitrary-length digest of data into hash.
func
ShakeSum256
(
hash
,
data
[]
byte
)
{
h
:=
NewShake256
()
h
.
Write
(
data
)
h
.
Read
(
hash
)
}
vendor/gx/QmSQRViqskLPYFbjKhWE5EaW8eou9SD2j52QaBkQdigMsG/crypto-sha3/testdata/keccakKats.json.deflate
deleted
100644 → 0
View file @
a40ef343
File deleted
vendor/gx/QmSQRViqskLPYFbjKhWE5EaW8eou9SD2j52QaBkQdigMsG/crypto-sha3/xor.go
deleted
100644 → 0
View file @
a40ef343
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !amd64,!386 appengine
package
sha3
var
(
xorIn
=
xorInGeneric
copyOut
=
copyOutGeneric
xorInUnaligned
=
xorInGeneric
copyOutUnaligned
=
copyOutGeneric
)
const
xorImplementationUnaligned
=
"generic"
vendor/gx/QmSQRViqskLPYFbjKhWE5EaW8eou9SD2j52QaBkQdigMsG/crypto-sha3/xor_generic.go
deleted
100644 → 0
View file @
a40ef343
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
sha3
import
"encoding/binary"
// xorInGeneric xors the bytes in buf into the state; it
// makes no non-portable assumptions about memory layout
// or alignment.
func
xorInGeneric
(
d
*
state
,
buf
[]
byte
)
{
n
:=
len
(
buf
)
/
8
for
i
:=
0
;
i
<
n
;
i
++
{
a
:=
binary
.
LittleEndian
.
Uint64
(
buf
)
d
.
a
[
i
]
^=
a
buf
=
buf
[
8
:
]
}
}
// copyOutGeneric copies ulint64s to a byte buffer.
func
copyOutGeneric
(
d
*
state
,
b
[]
byte
)
{
for
i
:=
0
;
len
(
b
)
>=
8
;
i
++
{
binary
.
LittleEndian
.
PutUint64
(
b
,
d
.
a
[
i
])
b
=
b
[
8
:
]
}
}
vendor/gx/QmSQRViqskLPYFbjKhWE5EaW8eou9SD2j52QaBkQdigMsG/crypto-sha3/xor_unaligned.go
deleted
100644 → 0
View file @
a40ef343
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build amd64 386
// +build !appengine
package
sha3
import
"unsafe"
func
xorInUnaligned
(
d
*
state
,
buf
[]
byte
)
{
bw
:=
(
*
[
maxRate
/
8
]
uint64
)(
unsafe
.
Pointer
(
&
buf
[
0
]))
n
:=
len
(
buf
)
if
n
>=
72
{
d
.
a
[
0
]
^=
bw
[
0
]
d
.
a
[
1
]
^=
bw
[
1
]
d
.
a
[
2
]
^=
bw
[
2
]
d
.
a
[
3
]
^=
bw
[
3
]
d
.
a
[
4
]
^=
bw
[
4
]
d
.
a
[
5
]
^=
bw
[
5
]
d
.
a
[
6
]
^=
bw
[
6
]
d
.
a
[
7
]
^=
bw
[
7
]
d
.
a
[
8
]
^=
bw
[
8
]
}
if
n
>=
104
{
d
.
a
[
9
]
^=
bw
[
9
]
d
.
a
[
10
]
^=
bw
[
10
]
d
.
a
[
11
]
^=
bw
[
11
]
d
.
a
[
12
]
^=
bw
[
12
]
}
if
n
>=
136
{
d
.
a
[
13
]
^=
bw
[
13
]
d
.
a
[
14
]
^=
bw
[
14
]
d
.
a
[
15
]
^=
bw
[
15
]
d
.
a
[
16
]
^=
bw
[
16
]
}
if
n
>=
144
{
d
.
a
[
17
]
^=
bw
[
17
]
}
if
n
>=
168
{
d
.
a
[
18
]
^=
bw
[
18
]
d
.
a
[
19
]
^=
bw
[
19
]
d
.
a
[
20
]
^=
bw
[
20
]
}
}
func
copyOutUnaligned
(
d
*
state
,
buf
[]
byte
)
{
ab
:=
(
*
[
maxRate
]
uint8
)(
unsafe
.
Pointer
(
&
d
.
a
[
0
]))
copy
(
buf
,
ab
[
:
])
}
var
(
xorIn
=
xorInUnaligned
copyOut
=
copyOutUnaligned
)
const
xorImplementationUnaligned
=
"unaligned"
vendor/gx/QmT98GixWnJUj3vHfoURNQa5uk8FxxmZVF5nv3AicXp2R1/yamux/LICENSE
deleted
100644 → 0
View file @
a40ef343
Mozilla Public License, version 2.0
1. Definitions
1.1. "Contributor"
means each individual or legal entity that creates, contributes to the
creation of, or owns Covered Software.
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used by a
Contributor and that particular Contributor's Contribution.
1.3. "Contribution"
means Covered Software of a particular Contributor.
1.4. "Covered Software"
means Source Code Form to which the initial Contributor has attached the
notice in Exhibit A, the Executable Form of such Source Code Form, and
Modifications of such Source Code Form, in each case including portions
thereof.
1.5. "Incompatible With Secondary Licenses"
means
a. that the initial Contributor has attached the notice described in
Exhibit B to the Covered Software; or
b. that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the terms of
a Secondary License.
1.6. "Executable Form"
means any form of the work other than Source Code Form.
1.7. "Larger Work"
means a work that combines Covered Software with other material, in a
separate file or files, that is not Covered Software.
1.8. "License"
means this document.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible, whether
at the time of the initial grant or subsequently, any and all of the
rights conveyed by this License.
1.10. "Modifications"
means any of the following:
a. any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered Software; or
b. any new file in Source Code Form that contains any Covered Software.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the License,
by the making, using, selling, offering for sale, having made, import,
or transfer of either its Contributions or its Contributor Version.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU Lesser
General Public License, Version 2.1, the GNU Affero General Public
License, Version 3.0, or any later versions of those licenses.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that controls, is
controlled by, or is under common control with You. For purposes of this
definition, "control" means (a) the power, direct or indirect, to cause
the direction or management of such entity, whether by contract or
otherwise, or (b) ownership of more than fifty percent (50%) of the
outstanding shares or beneficial ownership of such entity.
2. License Grants and Conditions
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
a. under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
b. under Patent Claims of such Contributor to make, use, sell, offer for
sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
a. for any code that a Contributor has removed from Covered Software; or
b. for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
c. under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights to
grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
Section 2.1.
3. Responsibilities
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
a. such Covered Software must also be made available in Source Code Form,
as described in Section 3.1, and You must inform recipients of the
Executable Form how they can obtain a copy of such Source Code Form by
reasonable means in a timely manner, at a charge no more than the cost
of distribution to the recipient; and
b. You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter the
recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty, or
limitations of liability) contained within the Source Code Form of the
Covered Software, except that You may alter any license notices to the
extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
If it is impossible for You to comply with any of the terms of this License
with respect to some or all of the Covered Software due to statute,
judicial order, or regulation then You must: (a) comply with the terms of
this License to the maximum extent possible; and (b) describe the
limitations and the code they affect. Such description must be placed in a
text file included with all distributions of the Covered Software under
this License. Except to the extent prohibited by statute or regulation,
such description must be sufficiently detailed for a recipient of ordinary
skill to be able to understand it.
5. Termination
5.1. The rights granted under this License will terminate automatically if You
fail to comply with any of its terms. However, if You become compliant,
then the rights granted under this License from a particular Contributor
are reinstated (a) provisionally, unless and until such Contributor
explicitly and finally terminates Your grants, and (b) on an ongoing
basis, if such Contributor fails to notify You of the non-compliance by
some reasonable means prior to 60 days after You have come back into
compliance. Moreover, Your grants from a particular Contributor are
reinstated on an ongoing basis if such Contributor notifies You of the
non-compliance by some reasonable means, this is the first time You have
received notice of non-compliance with this License from such
Contributor, and You become compliant prior to 30 days after Your receipt
of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
license agreements (excluding distributors and resellers) which have been
validly granted by You or Your distributors under this License prior to
termination shall survive termination.
6. Disclaimer of Warranty
Covered Software is provided under this License on an "as is" basis,
without warranty of any kind, either expressed, implied, or statutory,
including, without limitation, warranties that the Covered Software is free
of defects, merchantable, fit for a particular purpose or non-infringing.
The entire risk as to the quality and performance of the Covered Software
is with You. Should any Covered Software prove defective in any respect,
You (not any Contributor) assume the cost of any necessary servicing,
repair, or correction. This disclaimer of warranty constitutes an essential
part of this License. No use of any Covered Software is authorized under
this License except under this disclaimer.
7. Limitation of Liability
Under no circumstances and under no legal theory, whether tort (including
negligence), contract, or otherwise, shall any Contributor, or anyone who
distributes Covered Software as permitted above, be liable to You for any
direct, indirect, special, incidental, or consequential damages of any
character including, without limitation, damages for lost profits, loss of
goodwill, work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses, even if such party shall have been
informed of the possibility of such damages. This limitation of liability
shall not apply to liability for death or personal injury resulting from
such party's negligence to the extent applicable law prohibits such
limitation. Some jurisdictions do not allow the exclusion or limitation of
incidental or consequential damages, so this exclusion and limitation may
not apply to You.
8. Litigation
Any litigation relating to this License may be brought only in the courts
of a jurisdiction where the defendant maintains its principal place of
business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions. Nothing
in this Section shall prevent a party's ability to bring cross-claims or
counter-claims.
9. Miscellaneous
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides that
the language of a contract shall be construed against the drafter shall not
be used to construe this License against a Contributor.
10. Versions of the License
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses If You choose to distribute Source Code Form that is
Incompatible With Secondary Licenses under the terms of this version of
the License, the notice described in Exhibit B of this License must be
attached.
Exhibit A - Source Code Form License Notice
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file,
then You may include the notice in a location (such as a LICENSE file in a
relevant directory) where a recipient would be likely to look for such a
notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
This Source Code Form is "Incompatible
With Secondary Licenses", as defined by
the Mozilla Public License, v. 2.0.
\ No newline at end of file
vendor/gx/QmT98GixWnJUj3vHfoURNQa5uk8FxxmZVF5nv3AicXp2R1/yamux/README.md
deleted
100644 → 0
View file @
a40ef343
# Yamux
Yamux (Yet another Multiplexer) is a multiplexing library for Golang.
It relies on an underlying connection to provide reliability
and ordering, such as TCP or Unix domain sockets, and provides
stream-oriented multiplexing. It is inspired by SPDY but is not
interoperable with it.
Yamux features include:
*
Bi-directional streams
*
Streams can be opened by either client or server
*
Useful for NAT traversal
*
Server-side push support
*
Flow control
*
Avoid starvation
*
Back-pressure to prevent overwhelming a receiver
*
Keep Alives
*
Enables persistent connections over a load balancer
*
Efficient
*
Enables thousands of logical streams with low overhead
## Documentation
For complete documentation, see the associated
[
Godoc
](
http://godoc.org/github.com/hashicorp/yamux
)
.
## Specification
The full specification for Yamux is provided in the
`spec.md`
file.
It can be used as a guide to implementors of interoperable libraries.
## Usage
Using Yamux is remarkably simple:
```
go
func
client
()
{
// Get a TCP connection
conn
,
err
:=
net
.
Dial
(
...
)
if
err
!=
nil
{
panic
(
err
)
}
// Setup client side of yamux
session
,
err
:=
yamux
.
Client
(
conn
,
nil
)
if
err
!=
nil
{
panic
(
err
)
}
// Open a new stream
stream
,
err
:=
session
.
Open
()
if
err
!=
nil
{
panic
(
err
)
}
// Stream implements net.Conn
stream
.
Write
([]
byte
(
"ping"
))
}
func
server
()
{
// Accept a TCP connection
conn
,
err
:=
listener
.
Accept
()
if
err
!=
nil
{
panic
(
err
)
}
// Setup server side of yamux
session
,
err
:=
yamux
.
Server
(
conn
,
nil
)
if
err
!=
nil
{
panic
(
err
)
}
// Accept a stream
stream
,
err
:=
session
.
Accept
()
if
err
!=
nil
{
panic
(
err
)
}
// Listen for a message
buf
:=
make
([]
byte
,
4
)
stream
.
Read
(
buf
)
}
```
vendor/gx/QmT98GixWnJUj3vHfoURNQa5uk8FxxmZVF5nv3AicXp2R1/yamux/addr.go
deleted
100644 → 0
View file @
a40ef343
package
yamux
import
(
"fmt"
"net"
)
// hasAddr is used to get the address from the underlying connection
type
hasAddr
interface
{
LocalAddr
()
net
.
Addr
RemoteAddr
()
net
.
Addr
}
// yamuxAddr is used when we cannot get the underlying address
type
yamuxAddr
struct
{
Addr
string
}
func
(
*
yamuxAddr
)
Network
()
string
{
return
"yamux"
}
func
(
y
*
yamuxAddr
)
String
()
string
{
return
fmt
.
Sprintf
(
"yamux:%s"
,
y
.
Addr
)
}
// Addr is used to get the address of the listener.
func
(
s
*
Session
)
Addr
()
net
.
Addr
{
return
s
.
LocalAddr
()
}
// LocalAddr is used to get the local address of the
// underlying connection.
func
(
s
*
Session
)
LocalAddr
()
net
.
Addr
{
addr
,
ok
:=
s
.
conn
.
(
hasAddr
)
if
!
ok
{
return
&
yamuxAddr
{
"local"
}
}
return
addr
.
LocalAddr
()
}
// RemoteAddr is used to get the address of remote end
// of the underlying connection
func
(
s
*
Session
)
RemoteAddr
()
net
.
Addr
{
addr
,
ok
:=
s
.
conn
.
(
hasAddr
)
if
!
ok
{
return
&
yamuxAddr
{
"remote"
}
}
return
addr
.
RemoteAddr
()
}
// LocalAddr returns the local address
func
(
s
*
Stream
)
LocalAddr
()
net
.
Addr
{
return
s
.
session
.
LocalAddr
()
}
// LocalAddr returns the remote address
func
(
s
*
Stream
)
RemoteAddr
()
net
.
Addr
{
return
s
.
session
.
RemoteAddr
()
}
Prev
1
…
11
12
13
14
15
16
17
18
19
Next
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