Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to open websocket connection? #3907

Closed
bgadmin opened this issue May 8, 2017 · 6 comments
Closed

How to open websocket connection? #3907

bgadmin opened this issue May 8, 2017 · 6 comments
Labels
kind/support A question or request for support topic/libp2p Topic libp2p

Comments

@bgadmin
Copy link

bgadmin commented May 8, 2017

Is it possible to open websocket connection on go-ipfs node, and how?

I would like to setup something like:
'/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd'

@whyrusleeping whyrusleeping assigned ghost May 10, 2017
@whyrusleeping whyrusleeping added topic/libp2p Topic libp2p kind/support A question or request for support labels May 10, 2017
@ghost
Copy link

ghost commented May 11, 2017

You need:

  • An SSL cert matching the /dns4 or /dns6 name
  • go-ipfs listening on /ip4/127.0.0.1/tcp/8081/ws
    • 8081 is just an example
    • note that it's /ws here, not /wss -- go-ipfs can't currently do SSL, see the next point
  • nginx
    • configured with the SSL cert
    • listening on port 443
    • forwarding to 127.0.0.1:8081

I have a work-in-progress branch which simplifies this a bit, but that's the setup for now.

@bgadmin
Copy link
Author

bgadmin commented May 15, 2017

Ok thanks @lgierth this was helpful:+1:

@bgadmin bgadmin closed this as completed May 15, 2017
@JoseMiguelHerrera
Copy link

@lgierth Hi Lars I'm trying to do this to get my js-ipfs browser client directly talking to my go-ipfs node, and this thread is the only place I can find guidance on how to do this. I tried it but it doesn't work, I must be missing a piece.

The go-ipfs node is on AWS and has public IP 18.XXX.XX.XXX and private/internal IP 172.XX.XX.XX.
The node's addresses config looks like this:

"Addresses": { "API": "/ip4/172.XX.XX.XX/tcp/5001", "Announce": [], "Gateway": "/ip4/172.XX.XX.XX/tcp/8080", "NoAnnounce": [], "Swarm": [ "/ip4/172.XX.XX.XX/tcp/4001", "/ip6/::/tcp/4001", "/ip4/172.XX.XX.XX/tcp/4002/ws" ] },

I addd the /ws address as instructed. I assume this makes the node listen via a web socket on 4002.

I have nginx set up with a certificate made via certbot with the following config:

` server {
listen 80;
server_name mydomain.com;

#charset koi8-r;
#access_log  /var/log/nginx/host.access.log  main;

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

location /  {
    proxy_pass http://18.XXX.XX.XXX:4002;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

} `

Is this port forwarding being done correctly as you have described?

The last piece of the puzzle is the ipfs-js config in the browser. I've tried adding many addresses in the creation of the node like so:

const node = new IPFS({ config: { Bootstrap: [ "/ip4/mydomain.com/tcp/443" ], } });

But really I don't really know what would go here.

I keep getting "NotFoundError"...but I know for a fact that this hash is on my go-ipfs node.

Your help would greatly be appreciated!!!

@KrishnaPG
Copy link

Would really appreciate if someone can point to how a client can establish webSocket connection to a node, and gateway. Any examples would be very helpful.

@Stebalien
Copy link
Member

@KrishnaPG please ask on the forums (https://discuss.ipfs.io) and tag me. When you do, please expand on what you mean by "establish a webSocket connection" (connect to the API? gateway? libp2p?).

@ChrisHagglundWS
Copy link

ChrisHagglundWS commented Mar 8, 2021

would it be possible to have a config option in the go-ipfs which sets a TLS hostname, and then if that is set to have the go code set up a wss handler using a lets-encrypt cert, much along the lines of how this example sets out automatic cert obtaining? (example: https://blog.kowalczyk.info/article/Jl3G/https-for-free-in-go-with-little-help-of-lets-encrypt.html), so as to make this automatic and NOT need to set up nginx to support allowing the browser js-ipfs to connect to my go-ipfs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support A question or request for support topic/libp2p Topic libp2p
Projects
None yet
Development

No branches or pull requests

6 participants