mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-21 07:02:33 +08:00
cleanup from CR
This commit is contained in:
Godeps
blockstore
crypto
routing/dht/pb
4
Godeps/Godeps.json
generated
4
Godeps/Godeps.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"ImportPath": "github.com/jbenet/go-ipfs",
|
||||
"GoVersion": "go1.3.3",
|
||||
"GoVersion": "devel +9340f9f6dfc9 Fri Oct 31 00:48:57 2014 -0300",
|
||||
"Packages": [
|
||||
"./..."
|
||||
],
|
||||
@ -98,7 +98,7 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/jbenet/go-msgio",
|
||||
"Rev": "c9069ab79c95aa0686347b516972c7329c4391f2"
|
||||
"Rev": "ab0e7a0e111d7c7d814ad238bcbf3934efb76ac3"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/jbenet/go-multiaddr",
|
||||
|
@ -36,12 +36,8 @@ func (bs *blockstore) Get(k u.Key) (*blocks.Block, error) {
|
||||
if !ok {
|
||||
return nil, ValueTypeMismatch
|
||||
}
|
||||
//TODO: we *could* verify data coming in from the datastore here
|
||||
// but its probably very unecessary
|
||||
return &blocks.Block{
|
||||
Data: bdata,
|
||||
Multihash: mh.Multihash(k),
|
||||
}, nil
|
||||
|
||||
return blocks.NewBlockWithHash(bdata, mh.Multihash(k))
|
||||
}
|
||||
|
||||
func (bs *blockstore) Put(block *blocks.Block) error {
|
||||
|
@ -51,7 +51,7 @@ type PrivKey interface {
|
||||
// Generate a secret string of bytes
|
||||
GenSecret() []byte
|
||||
|
||||
Unencrypt(b []byte) ([]byte, error)
|
||||
Decrypt(b []byte) ([]byte, error)
|
||||
}
|
||||
|
||||
type PubKey interface {
|
||||
|
@ -71,7 +71,7 @@ func (sk *RsaPrivateKey) GetPublic() PubKey {
|
||||
return &RsaPublicKey{&sk.k.PublicKey}
|
||||
}
|
||||
|
||||
func (sk *RsaPrivateKey) Unencrypt(b []byte) ([]byte, error) {
|
||||
func (sk *RsaPrivateKey) Decrypt(b []byte) ([]byte, error) {
|
||||
return rsa.DecryptPKCS1v15(rand.Reader, sk.k, b)
|
||||
}
|
||||
|
||||
|
@ -276,7 +276,6 @@ func (s *SecurePipe) handleSecureIn(hashType, cipherType string, tIV, tCKey, tMK
|
||||
|
||||
hmacOk := hmac.Equal(data[mark:], expected)
|
||||
if !hmacOk {
|
||||
s.Duplex.In <- nil
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ It has these top-level messages:
|
||||
*/
|
||||
package spipe_pb
|
||||
|
||||
import proto "code.google.com/p/gogoprotobuf/proto"
|
||||
import proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
|
||||
import math "math"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
@ -96,7 +96,7 @@ func (m *Exchange) GetSignature() []byte {
|
||||
|
||||
type DataSig struct {
|
||||
Data []byte `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"`
|
||||
Sig []byte `protobuf:"bytes,2,opt,name=sig" json:"sig,omitempty"`
|
||||
Signature []byte `protobuf:"bytes,2,opt,name=signature" json:"signature,omitempty"`
|
||||
Id *uint64 `protobuf:"varint,3,opt,name=id" json:"id,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
@ -112,9 +112,9 @@ func (m *DataSig) GetData() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *DataSig) GetSig() []byte {
|
||||
func (m *DataSig) GetSignature() []byte {
|
||||
if m != nil {
|
||||
return m.Sig
|
||||
return m.Signature
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -15,6 +15,6 @@ message Exchange {
|
||||
|
||||
message DataSig {
|
||||
optional bytes data = 1;
|
||||
optional bytes sig = 2;
|
||||
optional bytes signature = 2;
|
||||
optional uint64 id = 3;
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ type SignedPipe struct {
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
|
||||
mesid uint64
|
||||
theirmesid uint64
|
||||
localMsgID uint64
|
||||
removeMsgID uint64
|
||||
}
|
||||
|
||||
// secureChallengeSize is a constant that determines the initial challenge, and every subsequent
|
||||
@ -77,6 +77,8 @@ func (sp *SignedPipe) tryRecv() ([]byte, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// reduceChallenge reduces a series of bytes into a
|
||||
// single uint64 we can use as a seed for message IDs
|
||||
func reduceChallenge(cha []byte) uint64 {
|
||||
var out uint64
|
||||
for _, b := range cha {
|
||||
@ -134,8 +136,8 @@ func (sp *SignedPipe) handshake() error {
|
||||
return context.Canceled
|
||||
}
|
||||
|
||||
// Unencrypt and verify their challenge
|
||||
unenc, err := sp.local.PrivKey().Unencrypt(theirEnc)
|
||||
// Decrypt and verify their challenge
|
||||
unenc, err := sp.local.PrivKey().Decrypt(theirEnc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -182,8 +184,8 @@ func (sp *SignedPipe) handshake() error {
|
||||
return errors.New("Incorrect signature on challenge")
|
||||
}
|
||||
|
||||
sp.theirmesid = reduceChallenge(challenge)
|
||||
sp.mesid = reduceChallenge(unenc)
|
||||
sp.removeMsgID = reduceChallenge(challenge)
|
||||
sp.localMsgID = reduceChallenge(unenc)
|
||||
|
||||
go sp.handleIn(theirPubKey)
|
||||
go sp.handleOut(sp.local.PrivKey())
|
||||
@ -235,14 +237,14 @@ func (sp *SignedPipe) handleOut(pk ci.PrivKey) {
|
||||
}
|
||||
|
||||
sdata.Data = data
|
||||
sdata.Sig = sig
|
||||
sdata.Id = proto.Uint64(sp.mesid)
|
||||
sdata.Signature = sig
|
||||
sdata.Id = proto.Uint64(sp.localMsgID)
|
||||
b, err := proto.Marshal(sdata)
|
||||
if err != nil {
|
||||
log.Error("Error marshaling signed data object: %s", err)
|
||||
return
|
||||
}
|
||||
sp.mesid++
|
||||
sp.localMsgID++
|
||||
|
||||
select {
|
||||
case sp.insecure.Out <- b:
|
||||
@ -273,7 +275,7 @@ func (sp *SignedPipe) handleIn(theirPubkey ci.PubKey) {
|
||||
log.Error("Failed to unmarshal sigdata object")
|
||||
continue
|
||||
}
|
||||
correct, err := theirPubkey.Verify(sdata.GetData(), sdata.GetSig())
|
||||
correct, err := theirPubkey.Verify(sdata.GetData(), sdata.GetSignature())
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
continue
|
||||
@ -283,11 +285,11 @@ func (sp *SignedPipe) handleIn(theirPubkey ci.PubKey) {
|
||||
continue
|
||||
}
|
||||
|
||||
if sdata.GetId() != sp.theirmesid {
|
||||
if sdata.GetId() != sp.removeMsgID {
|
||||
log.Critical("Out of order message id!")
|
||||
return
|
||||
}
|
||||
sp.theirmesid++
|
||||
sp.removeMsgID++
|
||||
|
||||
select {
|
||||
case <-sp.ctx.Done():
|
||||
|
@ -118,7 +118,7 @@ func runEncryptBenchmark(b *testing.B) {
|
||||
}()
|
||||
|
||||
data := make([]byte, 1024*512)
|
||||
util.NewFastRand().Read(data)
|
||||
util.NewTimeSeededRand().Read(data)
|
||||
// Begin actual benchmarking
|
||||
b.ResetTimer()
|
||||
|
||||
@ -170,7 +170,7 @@ func BenchmarkSignedChannel(b *testing.B) {
|
||||
}()
|
||||
|
||||
data := make([]byte, 1024*512)
|
||||
util.NewFastRand().Read(data)
|
||||
util.NewTimeSeededRand().Read(data)
|
||||
// Begin actual benchmarking
|
||||
b.ResetTimer()
|
||||
|
||||
@ -199,7 +199,7 @@ func BenchmarkDataTransfer(b *testing.B) {
|
||||
}()
|
||||
|
||||
data := make([]byte, 1024*512)
|
||||
util.NewFastRand().Read(data)
|
||||
util.NewTimeSeededRand().Read(data)
|
||||
// Begin actual benchmarking
|
||||
b.ResetTimer()
|
||||
|
||||
|
@ -13,7 +13,7 @@ It has these top-level messages:
|
||||
*/
|
||||
package dht_pb
|
||||
|
||||
import proto "code.google.com/p/gogoprotobuf/proto"
|
||||
import proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
|
||||
import math "math"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
Reference in New Issue
Block a user