{"record":{"id":"79d81ea65560f643","repo":"ipfs/kubo","slug":"getclosestpeers-not-supported-for-dht-type-t","errorCode":null,"errorMessage":"GetClosestPeers not supported for DHT type %T","messagePattern":"GetClosestPeers not supported for DHT type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/corehttp/routing.go","lineNumber":131,"sourceCode":"\n\tif r.n.DHTClient == nil {\n\t\treturn nil, fmt.Errorf(\"GetClosestPeers not supported: DHT is not available\")\n\t}\n\n\tswitch dhtClient := r.n.DHTClient.(type) {\n\tcase *dual.DHT:\n\t\t// Only use WAN DHT for public HTTP Routing API.\n\t\t// LAN DHT contains private network peers that should not be exposed publicly.\n\t\tif dhtClient.WAN == nil {\n\t\t\treturn nil, fmt.Errorf(\"GetClosestPeers not supported: WAN DHT is not available\")\n\t\t}\n\t\tpeers, err = dhtClient.WAN.GetClosestPeers(ctx, keyStr)\n\tcase *fullrt.FullRT:\n\t\tpeers, err = dhtClient.GetClosestPeers(ctx, keyStr)\n\tcase *dht.IpfsDHT:\n\t\tpeers, err = dhtClient.GetClosestPeers(ctx, keyStr)\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"GetClosestPeers not supported for DHT type %T\", r.n.DHTClient)\n\t}\n\n\t// A lookup cut short by the deadline returns the closest peers found so far\n\t// along with the context error. The HTTP routing server caps every request\n\t// (server.DefaultRoutingTimeout), so on a slow query this is the difference\n\t// between a useful answer and a 500.\n\tif err != nil && len(peers) == 0 {\n\t\treturn nil, err\n\t}\n\n\t// We have some DHT-closest peers. Find addresses for them.\n\t// The addresses should be in the peerstore.\n\trecords := make([]*types.PeerRecord, 0, len(peers))\n\tfor _, p := range peers {\n\t\taddrs := r.n.Peerstore.Addrs(p)\n\t\trAddrs := make([]types.Multiaddr, len(addrs))\n\t\tfor i, addr := range addrs {\n\t\t\trAddrs[i] = types.Multiaddr{Multiaddr: addr}","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/corehttp/routing.go#L113-L149","documentation":"Kubo's HTTP Routing API supports delegating GetClosestPeers to a known set of DHT client implementations (*dual.DHT, *fullrt.FullRT, *dht.IpfsDHT). If the node's DHTClient is any other type (or nil/uninitialized as a different type), the handler does not know how to perform the lookup and returns this error with the concrete Go type in the message. It acts as an exhaustiveness guard over the DHT type switch.","triggerScenarios":"Calling the GetClosestPeers HTTP Routing endpoint on a node whose `node.DHTClient` is set to an implementation outside the supported switch cases — e.g. a nil DHTClient, a custom/mock routing implementation, or a future DHT type not yet handled in core/corehttp/routing.go.","commonSituations":"Running a node built with custom routing (e.g. delegated routing only, `Routing.Type=delegated`, or `none`) so no supported DHT client is instantiated; embedding kubo as a library and injecting a custom DHTClient implementation; version drift where a new DHT type was added but corehttp/routing.go was not updated.","solutions":["Check the node's routing configuration and switch to a supported mode that instantiates a known DHT client: `ipfs config Routing.Type dhtclient` (or `dhtserver`) and restart the daemon.","If embedding kubo, ensure you assign one of the supported types (*dual.DHT, *fullrt.FullRT, *dht.IpfsDHT) to node.DHTClient.","If you maintain a fork or a new DHT implementation, add a case for that type in the type switch in core/corehttp/routing.go to dispatch GetClosestPeers appropriately.","As a client, catch this error and fail over to another routing provider that supports the operation."],"exampleFix":"// Embedder: before\nnode.DHTClient = myCustomRouter // unsupported type\n// after\nnode.DHTClient = dual.New(ctx, dhtLAN, dhtWAN) // or fullrt/dht.IpfsDHT","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func supportedDHT(n *core.IpfsNode) bool {\n    switch n.DHTClient.(type) {\n    case *dual.DHT, *fullrt.FullRT, *dht.IpfsDHT:\n        return true\n    default:\n        return false\n    }\n}","tryCatchPattern":"peers, err := rt.GetClosestPeers(ctx, key)\nif err != nil && strings.Contains(err.Error(), \"not supported for DHT type\") {\n    return useAlternativeRouting(ctx, key) // e.g. delegated routing client\n}","preventionTips":["Pin Routing.Type to dhtclient/dhtserver on nodes serving the HTTP Routing API","When embedding kubo, only assign supported DHTClient implementations","Extend the type switch in core/corehttp/routing.go when adding new DHT types","Cover the routing endpoint in tests for every supported routing mode"],"tags":["dht","routing","http-api","type-switch"],"backgroundTag":"unsupported-dht-type","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}