@@ -9,90 +9,12 @@ import (
9
9
"strings"
10
10
"time"
11
11
12
- "github.com/libp2p/go-libp2p/core/peer"
13
12
"github.com/multiformats/go-multiaddr"
14
13
15
- "github.com/waku-org/go-waku/waku/v2/protocol/enr"
16
- "github.com/waku-org/go-waku/waku/v2/utils"
17
-
18
- "github.com/ethereum/go-ethereum/p2p/enode"
19
-
20
14
"github.com/status-im/status-go/protocol/transport"
15
+ "github.com/status-im/status-go/waku/types"
21
16
)
22
17
23
- func MustDecodeENR (enrStr string ) * enode.Node {
24
- node , err := enode .Parse (enode .ValidSchemes , enrStr )
25
- if err != nil || node == nil {
26
- panic ("could not decode enr: " + enrStr )
27
- }
28
- return node
29
- }
30
-
31
- func MustDecodeMultiaddress (multiaddrsStr string ) * multiaddr.Multiaddr {
32
- maddr , err := multiaddr .NewMultiaddr (multiaddrsStr )
33
- if err != nil || maddr == nil {
34
- panic ("could not decode multiaddr: " + multiaddrsStr )
35
- }
36
- return & maddr
37
- }
38
-
39
- type Mailserver struct {
40
- ID string `json:"id"`
41
- Name string `json:"name"`
42
- Custom bool `json:"custom"`
43
- ENR * enode.Node `json:"enr"`
44
- Addr * multiaddr.Multiaddr `json:"addr"`
45
-
46
- // Deprecated: only used with WakuV1
47
- Password string `json:"password,omitempty"`
48
- Fleet string `json:"fleet"`
49
- FailedRequests uint `json:"-"`
50
- }
51
-
52
- func (m Mailserver ) PeerInfo () (peer.AddrInfo , error ) {
53
- var maddrs []multiaddr.Multiaddr
54
-
55
- if m .ENR != nil {
56
- addrInfo , err := enr .EnodeToPeerInfo (m .ENR )
57
- if err != nil {
58
- return peer.AddrInfo {}, err
59
- }
60
- addrInfo .Addrs = utils .EncapsulatePeerID (addrInfo .ID , addrInfo .Addrs ... )
61
- maddrs = append (maddrs , addrInfo .Addrs ... )
62
- }
63
-
64
- if m .Addr != nil {
65
- maddrs = append (maddrs , * m .Addr )
66
- }
67
-
68
- p , err := peer .AddrInfosFromP2pAddrs (maddrs ... )
69
- if err != nil {
70
- return peer.AddrInfo {}, err
71
- }
72
-
73
- if len (p ) != 1 {
74
- return peer.AddrInfo {}, errors .New ("invalid mailserver setup" )
75
- }
76
-
77
- return p [0 ], nil
78
- }
79
-
80
- func (m Mailserver ) PeerID () (peer.ID , error ) {
81
- p , err := m .PeerInfo ()
82
- if err != nil {
83
- return "" , err
84
- }
85
- return p .ID , nil
86
- }
87
-
88
- func (m Mailserver ) nullablePassword () (val sql.NullString ) {
89
- if m .Password != "" {
90
- val .String = m .Password
91
- val .Valid = true
92
- }
93
- return
94
- }
95
-
96
18
type MailserverRequestGap struct {
97
19
ID string `json:"id"`
98
20
ChatID string `json:"chatId"`
@@ -145,7 +67,7 @@ func NewDB(db *sql.DB) *Database {
145
67
return & Database {db : db }
146
68
}
147
69
148
- func (d * Database ) Add (mailserver Mailserver ) error {
70
+ func (d * Database ) Add (mailserver types. Mailserver ) error {
149
71
// TODO: we are only storing the multiaddress.
150
72
// In a future PR we must allow storing multiple multiaddresses and ENR
151
73
_ , err := d .db .Exec (`INSERT OR REPLACE INTO mailservers(
@@ -158,13 +80,13 @@ func (d *Database) Add(mailserver Mailserver) error {
158
80
mailserver .ID ,
159
81
mailserver .Name ,
160
82
(* mailserver .Addr ).String (),
161
- mailserver .nullablePassword (),
83
+ mailserver .NullablePassword (),
162
84
mailserver .Fleet ,
163
85
)
164
86
return err
165
87
}
166
88
167
- func (d * Database ) Mailservers () ([]Mailserver , error ) {
89
+ func (d * Database ) Mailservers () ([]types. Mailserver , error ) {
168
90
rows , err := d .db .Query (`SELECT id, name, address, password, fleet FROM mailservers` )
169
91
if err != nil {
170
92
return nil , err
@@ -173,12 +95,12 @@ func (d *Database) Mailservers() ([]Mailserver, error) {
173
95
return toMailservers (rows )
174
96
}
175
97
176
- func toMailservers (rows * sql.Rows ) ([]Mailserver , error ) {
177
- var result []Mailserver
98
+ func toMailservers (rows * sql.Rows ) ([]types. Mailserver , error ) {
99
+ var result []types. Mailserver
178
100
179
101
for rows .Next () {
180
102
var (
181
- m Mailserver
103
+ m types. Mailserver
182
104
addrStr string
183
105
password sql.NullString
184
106
)
0 commit comments