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

Reimplement a synchronous method - Fixes #13 #14

Merged
merged 2 commits into from
Sep 30, 2017
Merged

Reimplement a synchronous method - Fixes #13 #14

merged 2 commits into from
Sep 30, 2017

Conversation

shellscape
Copy link
Contributor

This PR makes use of a recent update to default-gateway which provides synchronous methods, to reimplement sync support in this module.

index.js Outdated
module.exports.v6 = () => internalIp('v6');
module.exports.v4 = () => internalIp('v4');
function sync(family) {
const result = defaultGateway[family].sync();
Copy link
Collaborator

@silverwind silverwind Sep 28, 2017

Choose a reason for hiding this comment

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

you need to wrap this line in a try...catch and return the defaults in case of error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do

index.js Outdated

return Boolean(ret);
});
function match(gateway, family) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe findIp might be a better name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

from line 16 // Look for the matching interface in all local interfaces - that's why I chose the name. doesn't much matter to me what you think it should be, happy to change it, but I thought it was appropriate given that comment

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I still think findIp is more appropriate. The matching is only part of the process.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aye, will change

const prefix = ipaddr.parse(addr.netmask).prefixLengthFromSubnetMask();
const net = ipaddr.parseCIDR(`${addr.address}/${prefix}`);

if (net[0].kind() === gatewayIp.kind() && gatewayIp.match(net)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

just noticed this: could you add a check for net[0] here, e.g. if (net[0] && net[0].kind()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a direct copy paste from the code as it presently is in master. mentioning only to confirm that you want to piggy back on this PR for the change

Copy link
Collaborator

Choose a reason for hiding this comment

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

right, I can fix that later myself, no need to do it here.

@sindresorhus sindresorhus changed the title resolves #13: reimplement a synchronous method Reimplement a synchronous method - Fixes #13 Sep 29, 2017
@silverwind silverwind merged commit 009f260 into sindresorhus:master Sep 30, 2017
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.

None yet

2 participants