forked from repbin/repbin
/
peers.go
51 lines (45 loc) · 1.82 KB
/
peers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package messagestore
import (
"github.com/agl/ed25519"
log "github.com/repbin/repbin/deferconsole"
"github.com/repbin/repbin/utils"
"github.com/repbin/repbin/utils/keyproof"
"github.com/repbin/repbin/utils/repproto/structs"
)
// TouchPeer creates a peer entry if it does not exist yet
func (store Store) TouchPeer(pubkey *[ed25519.PublicKeySize]byte) {
err := store.db.TouchPeer(pubkey)
if err != nil {
log.Errorf("TouchPeer: %s, %s\n", err, utils.B58encode(pubkey[:]))
}
}
// UpdatePeerFetchStat writes fetch-specific data
func (store Store) UpdatePeerFetchStat(pubkey *[ed25519.PublicKeySize]byte, lastFetch, lastPos, lastErrors uint64) {
err := store.db.UpdatePeerStats(pubkey, lastFetch, lastPos, lastErrors)
if err != nil {
log.Errorf("UpdatePeerStats: %s, %s\n", err, utils.B58encode(pubkey[:]))
}
}
// UpdatePeerNotification updates the peer stat after notification send
func (store Store) UpdatePeerNotification(pubkey *[ed25519.PublicKeySize]byte, hasError bool) {
err := store.db.UpdatePeerNotification(pubkey, hasError)
if err != nil {
log.Errorf("UpdatePeerNotification: %s, %s\n", err, utils.B58encode(pubkey[:]))
}
}
// GetPeerStat returns the last entry of peer statistics for pubkey
func (store Store) GetPeerStat(pubkey *[ed25519.PublicKeySize]byte) *structs.PeerStruct {
st, err := store.db.SelectPeer(pubkey)
if err != nil {
log.Errorf("GetPeerStat: %s, %s\n", err, utils.B58encode(pubkey[:]))
return nil
}
return st
}
// UpdatePeerAuthToken updates the peer record when a new auth token has been received
func (store Store) UpdatePeerAuthToken(senderPubKey *[ed25519.PublicKeySize]byte, signedToken *[keyproof.ProofTokenSignedSize]byte) {
err := store.db.UpdatePeerToken(senderPubKey, signedToken)
if err != nil {
log.Errorf("UpdatePeerAuthToken: %s, %s\n", err, utils.B58encode(senderPubKey[:]))
}
}