Commit 47e3ab13 authored by Steven Allen's avatar Steven Allen

validate protocol definition in add protocol

parent ece734f1
......@@ -120,6 +120,12 @@ func SwapToP2pMultiaddrs() {
}
func AddProtocol(p Protocol) error {
if p.Size != 0 && p.Transcoder == nil {
return fmt.Errorf("protocols with arguments must define transcoders")
}
if p.Path && p.Size >= 0 {
return fmt.Errorf("path protocols must have variable-length sizes")
}
for _, pt := range Protocols {
if pt.Code == p.Code {
return fmt.Errorf("protocol code %d already taken by %q", p.Code, pt.Name)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment