Skip to content

Commit

Permalink
enhancement/id (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
decanus authored Jul 12, 2019
1 parent d4e6314 commit ea60666
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (n *Node) AppendMessage(group state.GroupID, data []byte) (state.MessageID,
Body: data,
}

id := state.ID(m)
id := m.ID()

peers, ok := n.peers[group]
if !ok {
Expand Down Expand Up @@ -278,7 +278,7 @@ func (n *Node) onMessages(group state.GroupID, sender state.PeerID, messages []*
continue
}

id := state.ID(*m)
id := m.ID()
log.Printf("[%x] sending ACK (%x -> %x): %x\n", group[:4], n.ID[:4], sender[:4], id[:4])
a = append(a, id[:])
}
Expand All @@ -287,7 +287,7 @@ func (n *Node) onMessages(group state.GroupID, sender state.PeerID, messages []*
}

func (n *Node) onMessage(group state.GroupID, sender state.PeerID, msg protobuf.Message) error {
id := state.ID(msg)
id := msg.ID()
log.Printf("[%x] MESSAGE (%x -> %x): %x received.\n", group[:4], sender[:4], n.ID[:4], id[:4])

err := n.syncState.Remove(group, id, sender)
Expand Down
11 changes: 5 additions & 6 deletions state/sync_messageid.go → protobuf/messageid.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package state
package protobuf

import (
"crypto/sha256"
"encoding/binary"

"github.com/status-im/mvds/protobuf"
"github.com/status-im/mvds/state"
)

type MessageID [32]byte
type GroupID [32]byte

// ID creates the MessageID for a Message
func ID(m protobuf.Message) MessageID {
func (m Message) ID() state.MessageID {
t := make([]byte, 8)
binary.LittleEndian.PutUint64(t, uint64(m.Timestamp))

Expand All @@ -21,3 +18,5 @@ func ID(m protobuf.Message) MessageID {

return sha256.Sum256(b)
}


4 changes: 4 additions & 0 deletions state/sync_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package state

type MessageID [32]byte
type GroupID [32]byte
2 changes: 1 addition & 1 deletion store/messagestore_dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ func (ds *DummyStore) Get(id state.MessageID) (protobuf.Message, error) {
func (ds *DummyStore) Add(message protobuf.Message) error {
ds.Lock()
defer ds.Unlock()
ds.ms[state.ID(message)] = message
ds.ms[message.ID()] = message
return nil
}

0 comments on commit ea60666

Please sign in to comment.