cleanup from CR
Jeromy committed
Oct 31, 2014 at 06:26 UTC
5edbca2e7089aeecb503db9de98acdfaa1a70f9c
10 files changed
+29
-32
Godeps/Godeps.json
+2
-2
@@ -1,6 +1,6 @@
1
{
2
"ImportPath": "github.com/jbenet/go-ipfs",
3
- "GoVersion": "go1.3.3",
3
+ "GoVersion": "devel +9340f9f6dfc9 Fri Oct 31 00:48:57 2014 -0300",
4
"Packages": [
5
"./..."
6
],
@@ -98,7 +98,7 @@
98
},
99
{
100
"ImportPath": "github.com/jbenet/go-msgio",
101
- "Rev": "c9069ab79c95aa0686347b516972c7329c4391f2"
101
+ "Rev": "ab0e7a0e111d7c7d814ad238bcbf3934efb76ac3"
102
},
103
{
104
"ImportPath": "github.com/jbenet/go-multiaddr",
blockstore/blockstore.go
+2
-6
@@ -36,12 +36,8 @@ func (bs *blockstore) Get(k u.Key) (*blocks.Block, error) {
36
if !ok {
37
return nil, ValueTypeMismatch
38
}
39
- //TODO: we *could* verify data coming in from the datastore here
40
- // but its probably very unecessary
41
- return &blocks.Block{
42
- Data: bdata,
43
- Multihash: mh.Multihash(k),
44
- }, nil
39
+
40
+ return blocks.NewBlockWithHash(bdata, mh.Multihash(k))
41
}
42
43
func (bs *blockstore) Put(block *blocks.Block) error {
crypto/key.go
+1
-1
@@ -51,7 +51,7 @@ type PrivKey interface {
51
// Generate a secret string of bytes
52
GenSecret() []byte
53
54
- Unencrypt(b []byte) ([]byte, error)
54
+ Decrypt(b []byte) ([]byte, error)
55
}
56
57
type PubKey interface {
crypto/rsa.go
+1
-1
@@ -71,7 +71,7 @@ func (sk *RsaPrivateKey) GetPublic() PubKey {
71
return &RsaPublicKey{&sk.k.PublicKey}
72
}
73
74
-func (sk *RsaPrivateKey) Unencrypt(b []byte) ([]byte, error) {
74
+func (sk *RsaPrivateKey) Decrypt(b []byte) ([]byte, error) {
75
return rsa.DecryptPKCS1v15(rand.Reader, sk.k, b)
76
}
77
crypto/spipe/handshake.go
-1
@@ -276,7 +276,6 @@ func (s *SecurePipe) handleSecureIn(hashType, cipherType string, tIV, tCKey, tMK
276
277
hmacOk := hmac.Equal(data[mark:], expected)
278
if !hmacOk {
279
- s.Duplex.In <- nil
279
continue
280
}
281
crypto/spipe/internal/pb/spipe.pb.go
+4
-4
@@ -15,7 +15,7 @@ It has these top-level messages:
15
*/
16
package spipe_pb
17
18
-import proto "code.google.com/p/gogoprotobuf/proto"
18
+import proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
19
import math "math"
20
21
// Reference imports to suppress errors if they are not otherwise used.
@@ -96,7 +96,7 @@ func (m *Exchange) GetSignature() []byte {
96
97
type DataSig struct {
98
Data []byte `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"`
99
- Sig []byte `protobuf:"bytes,2,opt,name=sig" json:"sig,omitempty"`
99
+ Signature []byte `protobuf:"bytes,2,opt,name=signature" json:"signature,omitempty"`
100
Id *uint64 `protobuf:"varint,3,opt,name=id" json:"id,omitempty"`
101
XXX_unrecognized []byte `json:"-"`
102
}
@@ -112,9 +112,9 @@ func (m *DataSig) GetData() []byte {
112
return nil
113
}
114
115
-func (m *DataSig) GetSig() []byte {
115
+func (m *DataSig) GetSignature() []byte {
116
if m != nil {
117
- return m.Sig
117
+ return m.Signature
118
}
119
return nil
120
}
crypto/spipe/internal/pb/spipe.proto
+1
-1
@@ -15,6 +15,6 @@ message Exchange {
15
16
message DataSig {
17
optional bytes data = 1;
18
- optional bytes sig = 2;
18
+ optional bytes signature = 2;
19
optional uint64 id = 3;
20
}
crypto/spipe/signedpipe.go
+14
-12
@@ -25,8 +25,8 @@ type SignedPipe struct {
25
ctx context.Context
26
cancel context.CancelFunc
27
28
- mesid uint64
29
- theirmesid uint64
28
+ localMsgID uint64
29
+ removeMsgID uint64
30
}
31
32
// secureChallengeSize is a constant that determines the initial challenge, and every subsequent
@@ -77,6 +77,8 @@ func (sp *SignedPipe) tryRecv() ([]byte, bool) {
77
}
78
}
79
80
+// reduceChallenge reduces a series of bytes into a
81
+// single uint64 we can use as a seed for message IDs
82
func reduceChallenge(cha []byte) uint64 {
83
var out uint64
84
for _, b := range cha {
@@ -134,8 +136,8 @@ func (sp *SignedPipe) handshake() error {
136
return context.Canceled
137
}
138
137
- // Unencrypt and verify their challenge
138
- unenc, err := sp.local.PrivKey().Unencrypt(theirEnc)
139
+ // Decrypt and verify their challenge
140
+ unenc, err := sp.local.PrivKey().Decrypt(theirEnc)
141
if err != nil {
142
return err
143
}
@@ -182,8 +184,8 @@ func (sp *SignedPipe) handshake() error {
184
return errors.New("Incorrect signature on challenge")
185
}
186
185
- sp.theirmesid = reduceChallenge(challenge)
186
- sp.mesid = reduceChallenge(unenc)
187
+ sp.removeMsgID = reduceChallenge(challenge)
188
+ sp.localMsgID = reduceChallenge(unenc)
189
190
go sp.handleIn(theirPubKey)
191
go sp.handleOut(sp.local.PrivKey())
@@ -235,14 +237,14 @@ func (sp *SignedPipe) handleOut(pk ci.PrivKey) {
237
}
238
239
sdata.Data = data
238
- sdata.Sig = sig
239
- sdata.Id = proto.Uint64(sp.mesid)
240
+ sdata.Signature = sig
241
+ sdata.Id = proto.Uint64(sp.localMsgID)
242
b, err := proto.Marshal(sdata)
243
if err != nil {
244
log.Error("Error marshaling signed data object: %s", err)
245
return
246
}
245
- sp.mesid++
247
+ sp.localMsgID++
248
249
select {
250
case sp.insecure.Out <- b:
@@ -273,7 +275,7 @@ func (sp *SignedPipe) handleIn(theirPubkey ci.PubKey) {
275
log.Error("Failed to unmarshal sigdata object")
276
continue
277
}
276
- correct, err := theirPubkey.Verify(sdata.GetData(), sdata.GetSig())
278
+ correct, err := theirPubkey.Verify(sdata.GetData(), sdata.GetSignature())
279
if err != nil {
280
log.Error(err)
281
continue
@@ -283,11 +285,11 @@ func (sp *SignedPipe) handleIn(theirPubkey ci.PubKey) {
285
continue
286
}
287
286
- if sdata.GetId() != sp.theirmesid {
288
+ if sdata.GetId() != sp.removeMsgID {
289
log.Critical("Out of order message id!")
290
return
291
}
290
- sp.theirmesid++
292
+ sp.removeMsgID++
293
294
select {
295
case <-sp.ctx.Done():
crypto/spipe/spipe_test.go
+3
-3
@@ -118,7 +118,7 @@ func runEncryptBenchmark(b *testing.B) {
118
}()
119
120
data := make([]byte, 1024*512)
121
- util.NewFastRand().Read(data)
121
+ util.NewTimeSeededRand().Read(data)
122
// Begin actual benchmarking
123
b.ResetTimer()
124
@@ -170,7 +170,7 @@ func BenchmarkSignedChannel(b *testing.B) {
170
}()
171
172
data := make([]byte, 1024*512)
173
- util.NewFastRand().Read(data)
173
+ util.NewTimeSeededRand().Read(data)
174
// Begin actual benchmarking
175
b.ResetTimer()
176
@@ -199,7 +199,7 @@ func BenchmarkDataTransfer(b *testing.B) {
199
}()
200
201
data := make([]byte, 1024*512)
202
- util.NewFastRand().Read(data)
202
+ util.NewTimeSeededRand().Read(data)
203
// Begin actual benchmarking
204
b.ResetTimer()
205
routing/dht/pb/dht.pb.go
+1
-1
@@ -13,7 +13,7 @@ It has these top-level messages:
13
*/
14
package dht_pb
15
16
-import proto "code.google.com/p/gogoprotobuf/proto"
16
+import proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
17
import math "math"
18
19
// Reference imports to suppress errors if they are not otherwise used.