Skip to content

[Questions] Listeners and UDS #1234

@bitkis

Description

@bitkis

I was playing with chat example and ran into a couple of issues I hope you could help me with.

  1. After the following modification to chat.rs code has been made:
diff --git a/examples/chat.rs b/examples/chat.rs
index 65f8589..245b495 100644
--- a/examples/chat.rs
+++ b/examples/chat.rs
@@ -158,10 +160,10 @@ fn main() {
                 },
                 Async::Ready(None) | Async::NotReady => {
                     if !listening {
-                        if let Some(a) = Swarm::listeners(&swarm).next() {
-                            println!("Listening on {:?}", a);
-                            listening = true;
-                        }
+                        Swarm::listeners(&swarm).for_each(move |l| {
+                            println!("Listening on {:?}", l);
+                        });
+                        listening = true;
                     }
                     break
                 }

the output became

Local peer id: PeerId("QmbdG1dRD9SmWeDud6M79mGfh6kwWqmtQT4G2a69VYv3pn")
Listening on "/ip4/127.0.0.1/tcp/64039"
Listening on "/ip6/::1/tcp/64039"
Listening on "/ip4/127.94.0.1/tcp/64039"
Listening on "/ip4/192.168.1.77/tcp/64039"
Listening on "/ip4/192.168.1.66/tcp/64039"

It seems that, despite it being set to listen IPv4 (libp2p::Swarm::listen_on(&mut swarm, "/ip4/0.0.0.0/tcp/0".parse().unwrap()).unwrap(); on line 141), the app is listening on an interface with IPv6 address assigned.
Am I missing something or I'm hitting a bug?

  1. Actually, my goal at that moment was to enable unix domain socket, so I added the following code:
diff --git a/examples/chat.rs b/examples/chat.rs
index 65f8589..59a9f61 100644
--- a/examples/chat.rs
+++ b/examples/chat.rs
@@ -139,6 +139,7 @@ fn main() {

     // Listen on all interfaces and whatever port the OS assigns
     libp2p::Swarm::listen_on(&mut swarm, "/ip4/0.0.0.0/tcp/0".parse().unwrap()).unwrap();
+    libp2p::Swarm::listen_on(&mut swarm, "/unix//tmp/aaa".parse().unwrap()).unwrap();

     // Kick it off
     let mut listening = false;

Somehow that led to a run time error

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: UnknownProtocolString', src/libcore/result.rs:1084:5

And if I used "/unix/aaa" instead, the error became

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: MultiaddrNotSupported("/unix/buildmesh.QmPe33CVxLRYcBe62K4dKr7Lu4uUKgcKbMWz7TL8DT48aB")', src/libcore/result.rs:1084:5

Any idea what I missed there?

Thanks a lot in advance,
--Boris

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions