I am write a program that will provide some feature through a IPFS node. I want to able to identify my node from all peers. What’s the best way to do it? what I can think of it to encode a special key into it’s name or id or other information which will be returned from “ipfs swarm peers “ . but it seems IPFS does not allow that. Are there other ways to do it?
Maybe I didn’t make it clear. My program will run on many partners’ computer. There is no way I know the exact id. I was thinking to add some special informtion like a string in the id or othesr, so the node from my code could identify each other.
Why do you need to know which peers have your application running on them?
Perhaps a pub sub channel would work if the number of nodes aren’t too high. The application on each node could publish its peer ID to the application-specific channel at some interval so other nodes who are listening can know who they are.
There is no way to identify your peers from something like swarm peers. Without knowing what “service” they are going to provide and how it is hard to understand why you want your peers to be easily identifiable like that.
Also, IPFS does not currently have any “service discovery” mechanism by default (as in, announcing that a certain peer supports certain libp2p service), so you’d have to build your own (using pubsub as suggested above, or writing custom values directly to the DHT perhaps).
Thanks. Then I want to suggest to add such capacity. It could be very simple, like allow a peer to set a custom string and other peers are able to get it from swarm peers. It will be very light weight and open a lot of possiblities.
Here is an example,
we can write some code to make the node act as a http proxy (I believe some project already did it). If someone want to use this service, he must be able to find out such node from all peers. With this capacity, the proxy node could just SetCustomString(“httpProxy”). and other node could look for this string to identify the proxy.
This already happens at the protocol level. Your peer can test if other peers support certain libp2p protocol. What doesn’t exist, afaik, is a way to “find peers that support protocol X”.
Do you mean get support protocol info to identify? I tried to get it from ‘ipfs swarm peers —stream” and I can see some protocol info from connected peers, like ‘/ipfs/kad/1.0.0/‘ , but I don’t see the protocol I created through ‘ipfs p2p listen’, for example ‘/x/dd/1.0’, appear under my node info. Any suggestion ?