good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
069c87b9
Commit
069c87b9
authored
Mar 20, 2015
by
Felix Lange
Browse files
Options
Downloads
Patches
Plain Diff
whisper: use common.Hash
parent
7c4ff3ab
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
whisper/envelope.go
+14
-9
14 additions, 9 deletions
whisper/envelope.go
whisper/sort.go
+6
-2
6 additions, 2 deletions
whisper/sort.go
whisper/sort_test.go
+10
-6
10 additions, 6 deletions
whisper/sort_test.go
whisper/whisper.go
+4
-24
4 additions, 24 deletions
whisper/whisper.go
with
34 additions
and
41 deletions
whisper/envelope.go
+
14
−
9
View file @
069c87b9
...
@@ -18,26 +18,31 @@ const (
...
@@ -18,26 +18,31 @@ const (
type
Envelope
struct
{
type
Envelope
struct
{
Expiry
uint32
// Whisper protocol specifies int32, really should be int64
Expiry
uint32
// Whisper protocol specifies int32, really should be int64
T
tl
uint32
// ^^^^^^
T
TL
uint32
// ^^^^^^
Topics
[][]
byte
Topics
[][]
byte
Data
[]
byte
Data
[]
byte
Nonce
uint32
Nonce
uint32
hash
Hash
hash
common
.
Hash
}
}
func
(
self
*
Envelope
)
Hash
()
Hash
{
func
(
self
*
Envelope
)
Hash
()
common
.
Hash
{
if
self
.
hash
==
Empty
Hash
{
if
(
self
.
hash
==
common
.
Hash
{})
{
enc
,
_
:=
rlp
.
EncodeToBytes
(
self
)
enc
,
_
:=
rlp
.
EncodeToBytes
(
self
)
self
.
hash
=
H
(
crypto
.
Sha3
(
enc
)
)
self
.
hash
=
crypto
.
Sha3
Hash
(
enc
)
}
}
return
self
.
hash
return
self
.
hash
}
}
func
NewEnvelope
(
ttl
time
.
Duration
,
topics
[][]
byte
,
data
*
Message
)
*
Envelope
{
func
NewEnvelope
(
ttl
time
.
Duration
,
topics
[][]
byte
,
data
*
Message
)
*
Envelope
{
exp
:=
time
.
Now
()
.
Add
(
ttl
)
exp
:=
time
.
Now
()
.
Add
(
ttl
)
return
&
Envelope
{
return
&
Envelope
{
uint32
(
exp
.
Unix
()),
uint32
(
ttl
.
Seconds
()),
topics
,
data
.
Bytes
(),
0
,
Hash
{}}
Expiry
:
uint32
(
exp
.
Unix
()),
TTL
:
uint32
(
ttl
.
Seconds
()),
Topics
:
topics
,
Data
:
data
.
Bytes
(),
Nonce
:
0
,
}
}
}
func
(
self
*
Envelope
)
Seal
(
pow
time
.
Duration
)
{
func
(
self
*
Envelope
)
Seal
(
pow
time
.
Duration
)
{
...
@@ -104,7 +109,7 @@ func (self *Envelope) valid() bool {
...
@@ -104,7 +109,7 @@ func (self *Envelope) valid() bool {
}
}
func
(
self
*
Envelope
)
withoutNonce
()
interface
{}
{
func
(
self
*
Envelope
)
withoutNonce
()
interface
{}
{
return
[]
interface
{}{
self
.
Expiry
,
self
.
T
tl
,
self
.
Topics
,
self
.
Data
}
return
[]
interface
{}{
self
.
Expiry
,
self
.
T
TL
,
self
.
Topics
,
self
.
Data
}
}
}
// rlpenv is an Envelope but is not an rlp.Decoder.
// rlpenv is an Envelope but is not an rlp.Decoder.
...
@@ -119,6 +124,6 @@ func (self *Envelope) DecodeRLP(s *rlp.Stream) error {
...
@@ -119,6 +124,6 @@ func (self *Envelope) DecodeRLP(s *rlp.Stream) error {
if
err
:=
rlp
.
DecodeBytes
(
raw
,
(
*
rlpenv
)(
self
));
err
!=
nil
{
if
err
:=
rlp
.
DecodeBytes
(
raw
,
(
*
rlpenv
)(
self
));
err
!=
nil
{
return
err
return
err
}
}
self
.
hash
=
H
(
crypto
.
Sha3
(
raw
)
)
self
.
hash
=
crypto
.
Sha3
Hash
(
raw
)
return
nil
return
nil
}
}
This diff is collapsed.
Click to expand it.
whisper/sort.go
+
6
−
2
View file @
069c87b9
package
whisper
package
whisper
import
"sort"
import
(
"sort"
"github.com/ethereum/go-ethereum/common"
)
type
sortedKeys
struct
{
type
sortedKeys
struct
{
k
[]
int32
k
[]
int32
...
@@ -10,7 +14,7 @@ func (self *sortedKeys) Len() int { return len(self.k) }
...
@@ -10,7 +14,7 @@ func (self *sortedKeys) Len() int { return len(self.k) }
func
(
self
*
sortedKeys
)
Less
(
i
,
j
int
)
bool
{
return
self
.
k
[
i
]
<
self
.
k
[
j
]
}
func
(
self
*
sortedKeys
)
Less
(
i
,
j
int
)
bool
{
return
self
.
k
[
i
]
<
self
.
k
[
j
]
}
func
(
self
*
sortedKeys
)
Swap
(
i
,
j
int
)
{
self
.
k
[
i
],
self
.
k
[
j
]
=
self
.
k
[
j
],
self
.
k
[
i
]
}
func
(
self
*
sortedKeys
)
Swap
(
i
,
j
int
)
{
self
.
k
[
i
],
self
.
k
[
j
]
=
self
.
k
[
j
],
self
.
k
[
i
]
}
func
sortKeys
(
m
map
[
int32
]
Hash
)
[]
int32
{
func
sortKeys
(
m
map
[
int32
]
common
.
Hash
)
[]
int32
{
sorted
:=
new
(
sortedKeys
)
sorted
:=
new
(
sortedKeys
)
sorted
.
k
=
make
([]
int32
,
len
(
m
))
sorted
.
k
=
make
([]
int32
,
len
(
m
))
i
:=
0
i
:=
0
...
...
This diff is collapsed.
Click to expand it.
whisper/sort_test.go
+
10
−
6
View file @
069c87b9
package
whisper
package
whisper
import
"testing"
import
(
"testing"
"github.com/ethereum/go-ethereum/common"
)
func
TestSorting
(
t
*
testing
.
T
)
{
func
TestSorting
(
t
*
testing
.
T
)
{
m
:=
map
[
int32
]
Hash
{
m
:=
map
[
int32
]
common
.
Hash
{
1
:
HS
(
"1"
)
,
1
:
{
1
}
,
3
:
HS
(
"3"
)
,
3
:
{
3
}
,
2
:
HS
(
"2"
)
,
2
:
{
2
}
,
5
:
HS
(
"5"
)
,
5
:
{
5
}
,
}
}
exp
:=
[]
int32
{
1
,
2
,
3
,
5
}
exp
:=
[]
int32
{
1
,
2
,
3
,
5
}
res
:=
sortKeys
(
m
)
res
:=
sortKeys
(
m
)
...
...
This diff is collapsed.
Click to expand it.
whisper/whisper.go
+
4
−
24
View file @
069c87b9
package
whisper
package
whisper
import
(
import
(
"bytes"
"crypto/ecdsa"
"crypto/ecdsa"
"errors"
"errors"
"sync"
"sync"
"time"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/ecies"
"github.com/ethereum/go-ethereum/crypto/ecies"
"github.com/ethereum/go-ethereum/event/filter"
"github.com/ethereum/go-ethereum/event/filter"
...
@@ -15,26 +15,6 @@ import (
...
@@ -15,26 +15,6 @@ import (
"gopkg.in/fatih/set.v0"
"gopkg.in/fatih/set.v0"
)
)
// MOVE ME
type
Hash
struct
{
hash
string
}
var
EmptyHash
Hash
func
H
(
hash
[]
byte
)
Hash
{
return
Hash
{
string
(
hash
)}
}
func
HS
(
hash
string
)
Hash
{
return
Hash
{
hash
}
}
func
(
self
Hash
)
Compare
(
other
Hash
)
int
{
return
bytes
.
Compare
([]
byte
(
self
.
hash
),
[]
byte
(
other
.
hash
))
}
// MOVE ME END
const
(
const
(
statusMsg
=
0x0
statusMsg
=
0x0
envelopesMsg
=
0x01
envelopesMsg
=
0x01
...
@@ -55,7 +35,7 @@ type Whisper struct {
...
@@ -55,7 +35,7 @@ type Whisper struct {
filters
*
filter
.
Filters
filters
*
filter
.
Filters
mmu
sync
.
RWMutex
mmu
sync
.
RWMutex
messages
map
[
Hash
]
*
Envelope
messages
map
[
common
.
Hash
]
*
Envelope
expiry
map
[
uint32
]
*
set
.
SetNonTS
expiry
map
[
uint32
]
*
set
.
SetNonTS
quit
chan
struct
{}
quit
chan
struct
{}
...
@@ -65,7 +45,7 @@ type Whisper struct {
...
@@ -65,7 +45,7 @@ type Whisper struct {
func
New
()
*
Whisper
{
func
New
()
*
Whisper
{
whisper
:=
&
Whisper
{
whisper
:=
&
Whisper
{
messages
:
make
(
map
[
Hash
]
*
Envelope
),
messages
:
make
(
map
[
common
.
Hash
]
*
Envelope
),
filters
:
filter
.
New
(),
filters
:
filter
.
New
(),
expiry
:
make
(
map
[
uint32
]
*
set
.
SetNonTS
),
expiry
:
make
(
map
[
uint32
]
*
set
.
SetNonTS
),
quit
:
make
(
chan
struct
{}),
quit
:
make
(
chan
struct
{}),
...
@@ -239,7 +219,7 @@ func (self *Whisper) expire() {
...
@@ -239,7 +219,7 @@ func (self *Whisper) expire() {
}
}
hashSet
.
Each
(
func
(
v
interface
{})
bool
{
hashSet
.
Each
(
func
(
v
interface
{})
bool
{
delete
(
self
.
messages
,
v
.
(
Hash
))
delete
(
self
.
messages
,
v
.
(
common
.
Hash
))
return
true
return
true
})
})
self
.
expiry
[
then
]
.
Clear
()
self
.
expiry
[
then
]
.
Clear
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment