{"record":{"id":"e36d9f4145fd45fc","repo":"ipfs/kubo","slug":"failed-to-configure-private-network-s","errorCode":null,"errorMessage":"failed to configure private network: %s","messagePattern":"failed to configure private network: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/node/libp2p/pnet.go","lineNumber":29,"sourceCode":"\t\"github.com/libp2p/go-libp2p\"\n\t\"github.com/libp2p/go-libp2p/core/host\"\n\t\"github.com/libp2p/go-libp2p/core/pnet\"\n\t\"go.uber.org/fx\"\n\t\"golang.org/x/crypto/salsa20\"\n\t\"golang.org/x/crypto/sha3\"\n)\n\ntype PNetFingerprint []byte\n\nfunc PNet(repo repo.Repo) (opts Libp2pOpts, fp PNetFingerprint, err error) {\n\tswarmkey, err := repo.SwarmKey()\n\tif err != nil || swarmkey == nil {\n\t\treturn opts, nil, err\n\t}\n\n\tpsk, err := pnet.DecodeV1PSK(bytes.NewReader(swarmkey))\n\tif err != nil {\n\t\treturn opts, nil, fmt.Errorf(\"failed to configure private network: %s\", err)\n\t}\n\n\topts.Opts = append(opts.Opts, libp2p.PrivateNetwork(psk))\n\n\treturn opts, pnetFingerprint(psk), nil\n}\n\nfunc PNetChecker(repo repo.Repo, ph host.Host, lc fx.Lifecycle) error {\n\t// TODO: better check?\n\tswarmkey, err := repo.SwarmKey()\n\tif err != nil || swarmkey == nil {\n\t\treturn err\n\t}\n\n\tdone := make(chan struct{})\n\tlc.Append(fx.Hook{\n\t\tOnStart: func(_ context.Context) error {\n\t\t\tgo func() {","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/node/libp2p/pnet.go#L11-L47","documentation":"When a private network is configured (Swarm.Key exists in the repo), Kubo decodes the swarm key file as a libp2p V1 pre-shared key (pnet.DecodeV1PSK). If the file exists but its contents are not a valid 32-byte base16 PSK in the expected format, node construction fails wrapped with this error.","triggerScenarios":"Starting the daemon with a repo that contains a Swarm.Key file whose contents fail PSK decoding — wrong format, extra whitespace/BOM, truncated hex, or a key generated by a different/incompatible tool.","commonSituations":"Generating the swarm key by hand (correct format: a 32-byte hex key, optionally with the /key/swarm/psk/1.0.0/ multibase header); copying the key with newline/encoding corruption; mixing clusters' key files; placing a non-PSK file at Swarm.Key path.","solutions":["Regenerate or fix Swarm.Key to the canonical format: a line `KEY_TYPE` may be omitted and the body must be 64 hex chars, e.g. `echo -e \"/key/swarm/psk/1.0.0/\\n/base16/$(openssl rand -hex 32)\" > \"$IPFS_PATH/swarm.key\"`","Strip any BOM, CRLF, or trailing garbage from the existing swarm.key file (ensure plain ASCII with newline-separated header and key)","Verify which file is being used (`ipfs config --json Swarm` / check repo path) — you may be pointing at the wrong or corrupted key file"],"exampleFix":"// before (swarm.key)\nc29tZXRoaW5nLXNob3J0ZXIta2V5\n// after (swarm.key)\n/key/swarm/psk/1.0.0/\n/base16/0a1b2c3d4e5f60718293a4b5c6d7e8f90a1b2c3d4e5f60718293a4b5c6d7e8f9","handlingStrategy":"validation","validationCode":"b, err := os.ReadFile(keyPath)\nif err != nil { return err }\nif _, err := pnet.DecodeV1PSK(bytes.NewReader(b)); err != nil {\n    return fmt.Errorf(\"swarm key %s is not a valid V1 PSK: %w\", keyPath, err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate swarm keys with the canonical recipe: header /key/swarm/psk/1.0.0/ plus /base16/<64 hex chars>","Avoid hand-editing key files; regenerate instead of patching","Check for BOM/CRLF corruption when copying key files between machines"],"tags":["pnet","libp2p","config","swarm-key"],"backgroundTag":"invalid-swarm-key","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"}