From 47e3ab13b22b77c4c9221698be44c1df5fafce45 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 22 Jun 2018 18:34:55 -0700 Subject: [PATCH] validate protocol definition in add protocol --- protocols.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/protocols.go b/protocols.go index 175c5fe..5fe65b5 100644 --- a/protocols.go +++ b/protocols.go @@ -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)