mirror of
https://github.com/status-im/status-go.git
synced 2025-01-20 19:52:42 +00:00
eeca435064
Update vendor Integrate rendezvous into status node Add a test with failover using rendezvous Use multiple servers in client Use discovery V5 by default and test that node can be started with rendezvous discovet Fix linter Update rendezvous client to one with instrumented stream Address feedback Fix test with updated topic limits Apply several suggestions Change log to debug for request errors because we continue execution Remove web3js after rebase Update rendezvous package
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
package madns
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
ma "github.com/multiformats/go-multiaddr"
|
|
)
|
|
|
|
var Dns4Protocol = ma.Protocol{
|
|
Code: 54,
|
|
Size: ma.LengthPrefixedVarSize,
|
|
Name: "dns4",
|
|
VCode: ma.CodeToVarint(54),
|
|
Transcoder: DnsTranscoder,
|
|
}
|
|
var Dns6Protocol = ma.Protocol{
|
|
Code: 55,
|
|
Size: ma.LengthPrefixedVarSize,
|
|
Name: "dns6",
|
|
VCode: ma.CodeToVarint(55),
|
|
Transcoder: DnsTranscoder,
|
|
}
|
|
var DnsaddrProtocol = ma.Protocol{
|
|
Code: 56,
|
|
Size: ma.LengthPrefixedVarSize,
|
|
Name: "dnsaddr",
|
|
VCode: ma.CodeToVarint(56),
|
|
Transcoder: DnsTranscoder,
|
|
}
|
|
|
|
func init() {
|
|
err := ma.AddProtocol(Dns4Protocol)
|
|
if err != nil {
|
|
panic(fmt.Errorf("error registering dns4 protocol: %s", err))
|
|
}
|
|
err = ma.AddProtocol(Dns6Protocol)
|
|
if err != nil {
|
|
panic(fmt.Errorf("error registering dns6 protocol: %s", err))
|
|
}
|
|
err = ma.AddProtocol(DnsaddrProtocol)
|
|
if err != nil {
|
|
panic(fmt.Errorf("error registering dnsaddr protocol: %s", err))
|
|
}
|
|
}
|
|
|
|
var DnsTranscoder = ma.NewTranscoderFromFunctions(dnsStB, dnsBtS)
|
|
|
|
func dnsStB(s string) ([]byte, error) {
|
|
size := ma.CodeToVarint(len(s))
|
|
b := append(size, []byte(s)...)
|
|
return b, nil
|
|
}
|
|
|
|
func dnsBtS(b []byte) (string, error) {
|
|
size, n, err := ma.ReadVarintCode(b)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
b = b[n:]
|
|
if len(b) != size {
|
|
return "", errors.New("inconsistent lengths")
|
|
}
|
|
return string(b), nil
|
|
}
|