MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / bindRouteLocally

Method bindRouteLocally

pkg/wshutil/wshrouter.go:767–798  ·  view source on GitHub ↗
(linkId baseds.LinkId, routeId string, isSourceRoute bool)

Source from the content-addressed store, hash-verified

765}
766
767func (router *WshRouter) bindRouteLocally(linkId baseds.LinkId, routeId string, isSourceRoute bool) error {
768 if linkId == baseds.NoLinkId {
769 return fmt.Errorf("cannot bindroute %q to NoLinkId", routeId)
770 }
771 if !isBindableRouteId(routeId) {
772 return fmt.Errorf("router cannot register %q route (invalid routeid)", routeId)
773 }
774 router.lock.Lock()
775 defer router.lock.Unlock()
776 lm := router.linkMap[linkId]
777 if lm == nil {
778 return fmt.Errorf("cannot bind route %q, no link with id %d found", routeId, linkId)
779 }
780 if !lm.trusted {
781 return fmt.Errorf("cannot bind route %q, link %d is not trusted", routeId, linkId)
782 }
783 if isSourceRoute {
784 if lm.linkKind != LinkKind_Leaf {
785 return fmt.Errorf("cannot bind source route %q to link %d (link is not a leaf)", routeId, linkId)
786 }
787 if lm.sourceRouteId != "" && lm.sourceRouteId != routeId {
788 return fmt.Errorf("cannot bind source route %q to link %d (link already has source route %q)", routeId, linkId, lm.sourceRouteId)
789 }
790 lm.sourceRouteId = routeId
791 } else {
792 if lm.linkKind != LinkKind_Router {
793 return fmt.Errorf("cannot bind route %q to link %d (link is not a router)", routeId, linkId)
794 }
795 }
796 router.routeMap[routeId] = linkId
797 return nil
798}
799
800func (router *WshRouter) bindRoute(linkId baseds.LinkId, routeId string, isSourceRoute bool) error {
801 err := router.bindRouteLocally(linkId, routeId, isSourceRoute)

Callers 1

bindRouteMethod · 0.95

Calls 1

isBindableRouteIdFunction · 0.85

Tested by

no test coverage detected