2014-07-04 06:42:24 +00:00
|
|
|
package multiaddr
|
|
|
|
|
|
|
|
type Protocol struct {
|
2014-07-04 18:21:39 +00:00
|
|
|
Code int
|
|
|
|
Size int
|
|
|
|
Name string
|
2014-07-04 06:42:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// replicating table here to:
|
|
|
|
// 1. avoid parsing the csv
|
|
|
|
// 2. ensuring errors in the csv don't screw up code.
|
|
|
|
// 3. changing a number has to happen in two places.
|
|
|
|
|
2014-07-04 07:12:05 +00:00
|
|
|
var Protocols = []*Protocol{
|
2014-07-04 18:21:39 +00:00
|
|
|
&Protocol{4, 32, "ip4"},
|
|
|
|
&Protocol{6, 16, "tcp"},
|
|
|
|
&Protocol{17, 16, "udp"},
|
|
|
|
&Protocol{33, 16, "dccp"},
|
|
|
|
&Protocol{41, 128, "ip6"},
|
|
|
|
// these require varint:
|
|
|
|
&Protocol{132, 16, "sctp"},
|
|
|
|
// {480, 0, "http"},
|
|
|
|
// {443, 0, "https"},
|
2014-07-04 06:42:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ProtocolWithName(s string) *Protocol {
|
2014-07-04 18:21:39 +00:00
|
|
|
for _, p := range Protocols {
|
|
|
|
if p.Name == s {
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2014-07-04 06:42:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ProtocolWithCode(c int) *Protocol {
|
2014-07-04 18:21:39 +00:00
|
|
|
for _, p := range Protocols {
|
|
|
|
if p.Code == c {
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2014-07-04 06:42:24 +00:00
|
|
|
}
|