-
Notifications
You must be signed in to change notification settings - Fork 3
/
protocols.go
58 lines (46 loc) · 1.14 KB
/
protocols.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
52
53
54
55
56
57
58
package star
import (
ma "github.com/multiformats/go-multiaddr"
"github.com/multiformats/go-multiaddr-fmt"
)
const (
ipfsProtocolName = "ipfs"
webRTCStarProtocolCode = 499
webRTCStarProtocolName = "p2p-webrtc-star"
wsProtocolCode = 477
wssProtocolCode = 498
wssProtocolName = "wss"
)
var (
protocol = mustCreateProtocol(webRTCStarProtocolCode, webRTCStarProtocolName)
protocolMultiaddr ma.Multiaddr
wssProtocol = mustCreateProtocol(wssProtocolCode, wssProtocolName)
format = mafmt.And(mafmt.TCP,
mafmt.Or(mafmt.Base(wssProtocol.Code), mafmt.Base(wsProtocolCode)),
mafmt.Base(webRTCStarProtocolCode))
)
func init() {
mustAddProtocol(wssProtocol)
mustAddProtocol(protocol)
mustCreateStarMultiaddr()
}
func mustCreateStarMultiaddr() {
var err error
protocolMultiaddr, err = ma.NewMultiaddr("/" + webRTCStarProtocolName)
if err != nil {
logger.Fatal(err)
}
}
func mustAddProtocol(protocol ma.Protocol) {
err := ma.AddProtocol(protocol)
if err != nil {
logger.Fatal(err)
}
}
func mustCreateProtocol(code int, name string) ma.Protocol {
return ma.Protocol{
Code: code,
Name: name,
VCode: ma.CodeToVarint(code),
}
}