kubo icon indicating copy to clipboard operation
kubo copied to clipboard

p2p listen keep job running

Open Hazematman opened this issue 2 weeks ago • 5 comments

Checklist

  • [x] My issue is specific & actionable.
  • [x] I am not suggesting a protocol enhancement.
  • [x] I have searched on the issue tracker for my issue.

Description

It would be nice if ipfs p2p listen kept a process running in the foreground or had an option to leave a process running in the foreground. This way you could add it to a systemd service for example to have it automatically forward connections when a machine turns on or when it connects to the internet.

I'm not sure how kubo handles p2p listens in the background and if it tries to keep it running if connectivity drops or if the daemon shutdown.

Hazematman avatar Dec 08 '25 03:12 Hazematman

i recently wondered about this and in my application i resolved to just use the rpc api to control the listeners

you can get systemd to run

curl -X POST "http://127.0.0.1:5001/api/v0/p2p/listen?arg=&arg=&allow-custom-protocol=&report-peer-id="

its documented here https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-p2p-listen

amias-channer avatar Dec 08 '25 21:12 amias-channer

I'm sort of doing something similar. I wrapped launching the ipfs daemon with a script and that script will start the listen after the daemon comes up. My concern was more around if the listen fails for some reason. To check if it fails the only method I know of is the to check with p2p ls and then restart it. In my use case I want the listen to run when the machine starts up forever basically.

Hazematman avatar Dec 09 '25 00:12 Hazematman

You can write your own scripts with CLI or curl talking to HTTP Kubo RPC API, as noted in https://github.com/ipfs/kubo/issues/11087#issuecomment-3603887209, but having a flag that keeps p2p tunnel in foreground, and shuts it down when command exits makes sense for scripting and services like systemd.

I had a PoC for this very thing in a local branch, this issue motivated me to finish it:

  • https://github.com/ipfs/kubo/pull/11099

Would be very useful if you've built that PR and tested ipfs p2p listen --foreground + comment on that PR.

lidel avatar Dec 10 '25 01:12 lidel

@lidel Thanks, I tried that PR and it seems to work! Reading the code there a bit though I realized that the forwarding/listening is managed all through the daemon. Will the daemon keep the forwarding/listening running if the ipfs connection is lost and then reconnects? If so I think this feature might not be needed for my use case. I can just add a oneshot systemd job.

My main concern was making sure the p2p listen is relaunched if for some reason it dies.

Hazematman avatar Dec 10 '25 04:12 Hazematman

@Hazematman thats the point of --forgeround (to give you visibility and full control).

If you don't pass it, then the tunnel will work as long daemon is running or until someone ipfs p2p close it. You will not know when it breaks without active probing. If you pass --foreground, then you will see when tunnel breaks (due to any reason, manual close, process being killed, or daemon shutting down).

lidel avatar Dec 10 '25 18:12 lidel