2014-07-04 06:42:24 +00:00
|
|
|
package multiaddr
|
|
|
|
|
|
|
|
type Protocol struct {
|
|
|
|
Code int
|
|
|
|
Size int
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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{
|
|
|
|
&Protocol{4, 32, "ip4"},
|
|
|
|
&Protocol{6, 16, "tcp"},
|
|
|
|
&Protocol{17, 16, "udp"},
|
|
|
|
&Protocol{33, 16, "dccp"},
|
|
|
|
&Protocol{41, 128, "ip6"},
|
2014-07-04 06:42:24 +00:00
|
|
|
// these require varint:
|
2014-07-04 07:12:05 +00:00
|
|
|
&Protocol{132, 16, "sctp"},
|
2014-07-04 06:42:24 +00:00
|
|
|
// {480, 0, "http"},
|
|
|
|
// {443, 0, "https"},
|
|
|
|
}
|
|
|
|
|
|
|
|
func ProtocolWithName(s string) *Protocol {
|
|
|
|
for _, p := range(Protocols) {
|
|
|
|
if p.Name == s {
|
2014-07-04 07:12:05 +00:00
|
|
|
return p
|
2014-07-04 06:42:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ProtocolWithCode(c int) *Protocol {
|
|
|
|
for _, p := range(Protocols) {
|
|
|
|
if p.Code == c {
|
2014-07-04 07:12:05 +00:00
|
|
|
return p
|
2014-07-04 06:42:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|