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

iOS Ping functionality #602

Merged
merged 13 commits into from
Feb 27, 2019
Merged

iOS Ping functionality #602

merged 13 commits into from
Feb 27, 2019

Conversation

robmaceachern
Copy link
Contributor

Fixes #463

This adds a rudimentary SCPingUtility that is triggered via the (i) menu -> Ping Cogeco Peer 1. Peer 1 is supposed to supply us with some hostnames to ping but in the meantime I've added three for test purposes (note: cogecopeer1.com does not respond to pings):

("Cogeco Peer 1", "www.cogecopeer1.com"),
("Google", "www.google.com"),
("Yahoo", "www.yahoo.com")

When an entry is selected by the user, we do some lookups: hostname -> IP -> ANS. If the ANS is found and we know about it, we select the node on the map and automatically trigger the ping to the IP found during the lookup process.

@apike I don't know how soon we'll have the peer1 hostnames. If it might be a while, we could rename the menu item from "Ping Cogeco Peer1" to "Ping Popular Hosts" or something else and add a few more hostnames that we choose.

@apike apike self-assigned this Feb 24, 2019
@ssawchenko
Copy link
Contributor

Testing it out, when "Cogeco Peer 1" is selected from the Ping Us menu, the node for "Zenedge LLC" is shown.

screen shot 2019-02-25 at 1 05 44 pm

I'm not sure this is correct, since if you search for Cogeco Peer 1 in the Search window there are multiple ASNs that correspond to that name.

screen shot 2019-02-25 at 1 06 46 pm

I would assume the Ping for one of those would be what we would want to show? Perhaps it is the case here that the URL www.cogecopeer1.com is being hosted at a location that is being serviced by a different ASN?

@robmaceachern
Copy link
Contributor Author

Perhaps it is the case here that the URL www.cogecopeer1.com is being hosted at a location that is being serviced by a different ASN?

Yeah I've seen that hostname resolve to 152.70.44.18 and 205.147.88.248, both of which are part of the ZENEDGE ASN according to this online lookup tool.

$ nslookup www.cogecopeer1.com
Server:		192.168.1.1
Address:	192.168.1.1#53

Non-authoritative answer:
www.cogecopeer1.com	canonical name = cogecopeer1.com.
Name:	cogecopeer1.com
Address: 152.70.44.18

The current ping behaviour is consistent with what a user would see if they looked up the www.cogecopeer1.com hostname with the 'Find host...' search functionality.

simulator screen shot - iphone x - 2019-02-25 at 13 25 53

Copy link
Member

@nbrooke nbrooke left a comment

Choose a reason for hiding this comment

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

Mostly looks reasonable to me, couple of very minor comments, but they are all pretty judgment-call / optional sort of things, so I don't think merge should be blocked on any of them.

@objc var delegate: SCPingUtilityDelegate?

@objc public var packetRecords: [SCPacketRecord] {
let records = icmpUtility.packetRecords as! [SCPacketRecord]
Copy link
Member

Choose a reason for hiding this comment

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

Force cast here seems like it shouldn't be necessary, as the ObjC code is annotated with the right type. Was it maybe from before the annotation as added and never got removed?

Alternatively, is it maybe complaining because it things it might be nullable, and there needs to be a nullable annotation on that as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I was confused by this too. For some reason the generic type isn't bridging to Swift. The interface swift sees is:

var packetRecords: NSMutableArray! { get }

A bit of google searching led me to this Swift bug: Swift does not honor NSMutableArray generics from objective-c classes. I could try the workaround of changing the public interface to NSArray<SCPacketRecord *> as long as nothing else depends on modifying that array.

@@ -109,22 +109,19 @@ public class CreditsViewController: UIViewController, UIWebViewDelegate {
doneButton.layer.cornerRadius = doneButton.frame.size.height / 2
view.addSubview(doneButton)

// iPhoneX support
if #available(iOS 11.0, *) {
Copy link
Member

Choose a reason for hiding this comment

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

I assume this availbility is going away because the minimum platform is iOS 11 now, It looks like there is one other one that is still there, should maybe remove that as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

It looks like there is some inconsistency with the target and project ios deployment target settings so I'll try to fix that too.

backgroundImageView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
backgroundImageView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
backgroundImageView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
backgroundImageView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
Copy link
Member

Choose a reason for hiding this comment

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

Not sure how important it is, but it looks like there are at least 3 places (maybe more not included in this change) that we do this "turn of autoresizing mask and then pin to the same edges of the superview" thing. Might be worth having a utility function or category to do this as a one liner?

Not sure if it's worth it though, 3 copy-and-pastes is right no the edge of where I'd say it's a no-brainer to have a utility function, so if that's all there is maybe it's not actually worth it.

Other option would be to wait until NEXT time we have to do something like this, and just add SnapKit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I would like to bring in Snapkit but I figured we should sort out all the other out of date dependencies (#596) before bringing in a new one. If you feel strongly that this boilerplate-y autolayout code should be improved now, then I can bring it in sooner. Developing our own helpers would be kind of fun but I feel like I'd just end up reimplementing Snapkit's nice interface:

box.snp.makeConstraints { (make) -> Void in
    make.edges.equalTo(superview)
}

😍

@robmaceachern
Copy link
Contributor Author

@nbrooke let me know what you think about 2bc5783

I can't really tell what's best practice in Obj-C for this. Alternatively we could change the type of the packetRecords instance variable to NSMutableArray but then we need to access it directly when adding items, which felt wrong.

Copy link
Member

@nbrooke nbrooke left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me, it's a bit of a shame that it gets so gnarly to expose a reasonable interface for the packet records to Swift, but I think what you've got is a reasonable work around, and if we are going to have annoying warts better to have them in the ObjC code then the Swift code.

🚀

@robmaceachern robmaceachern merged commit d49d746 into master Feb 27, 2019
@robmaceachern robmaceachern deleted the rnm/463-ping branch February 27, 2019 19:27
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.

4 participants