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

Add gateway address to the returned IPFS api #145

Merged
merged 4 commits into from
Feb 16, 2017
Merged

Conversation

haadcode
Copy link
Member

@haadcode haadcode commented Jan 4, 2017

This PR will add a properties to get the address the gateway was started at and can be accessed with:

ipfs.gatewayHost
ipfs.gatewayPort

@haadcode haadcode added the status/in-progress In progress label Jan 4, 2017
@dignifiedquire
Copy link
Member

CI is very unhappy here

@haadcode
Copy link
Member Author

Fixed!

src/node.js Outdated
@@ -198,6 +198,7 @@ class Node {
},
data: (data) => {
const match = String(data).trim().match(/API server listening on (.*)/)
const gwmatch = String(data).trim().match(/Gateway (.*) listening on (.*)/)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not duplicate work. The trim and string cast are happening twice now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix this.

src/node.js Outdated
@@ -206,6 +207,13 @@ class Node {
this.api.apiHost = addr.address
this.api.apiPort = addr.port

if (gwmatch) {
this.gatewayAddr = gwmatch[2]
const addr = multiaddr(this.gatewayAddr).nodeAddress()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about only exposing this.gatewayAddr = multiaddr(gwmatch[2]). That way we have the standard multiaddr we are using everywhere and you can pull the details you need at any point.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe following the current convention as per api host and port is a better approach for consistency.

We can do what you propose in separate PR, bearing in mind it would be a public API change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is the a breaking change, currently the gatewayAddr doesn't exist from what I can tell?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jumped some steps here :) Let me try again:

We currently have (with this PR):

ipfs.apiHost
ipfs.apiPort
ipfs.gatewayHost
ipfs.gatewayPort

If we would expose the addresses as multiaddr, we should make sure the properties are consistent:

ipfs.apiAddr
ipfs.gatewayAddr

So with that, I would get rid of ipfs.apiHost and ipfs.apiPort, and that would be the breaking change.

Does that make sense? We could also add both ipfs.gatewayAddr and ipfs.apiAddr in this PR, but then we'd have the apiHost and apiPort still there and I think that'd be slightly more confusion to have same thing as multiple properties.

Let me know what you think!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about exposing gatewayAddr and apiAddr as the main thing, and making the others simple helper functions which just depend on those?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the code now to expose apiAddr and gatewayAddr in the Node and to keep api compatibility, keep the separate variables for host and port in the ipfs instance. I'm not a huge fan of the monkey-patching solution here as it changed the public API of js-ipfs-api, but that's how it's always been, so I don't want to break that now.

@dignifiedquire take a look at let me know if you think this is good to go.

@daviddias daviddias added status/ready Ready to be worked and removed status/in-progress In progress labels Jan 19, 2017
@haadcode haadcode force-pushed the feat/gateway-address branch from 39d54f5 to f308af2 Compare February 14, 2017 13:13
@haadcode
Copy link
Member Author

As noticed on IRC, this will change the public property apiAddr from string to multiaddr. We should prolly bump the version? Should I bump it to 0.19.0?

@dignifiedquire
Copy link
Member

version bump will happen on release.

@haadcode haadcode mentioned this pull request Feb 15, 2017
@daviddias
Copy link
Member

daviddias commented Feb 15, 2017

  • Needs deps to be updated (npm-go-ipfs)

Are there PRs to cope with the breaking change proposed here?

@haadcode
Copy link
Member Author

Are there PRs to cope with the breaking change proposed here?

This will change the public API of ipfsd-ctl, not the ipfs API returned by it. Ie. nothing should break for js-ipfs-api. Do we test this module somewhere else than here in its own tests?

@daviddias
Copy link
Member

Just to be sure, can you check if js-ipfs-api runs smoothly with these changes?

@daviddias daviddias merged commit e56462f into master Feb 16, 2017
@daviddias daviddias deleted the feat/gateway-address branch February 16, 2017 11:32
@daviddias daviddias removed the status/ready Ready to be worked label Feb 16, 2017
@haadcode
Copy link
Member Author

Just to be sure, can you check if js-ipfs-api runs smoothly with these changes?

Sure thing! I'll add tests to js-ipfs-api for this today.

@daviddias
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants