vouch-opensource / krell

Simple ClojureScript React Native Tooling
Eclipse Public License 1.0
675 stars 37 forks source link

Providing more control over the server-ip picked for the repl #102

Closed olivergeorge closed 4 years ago

olivergeorge commented 4 years ago

We're finding get-ip picks a bad ip address when we're using a VPN. As a result the app can't connect to the repl.

As a specific example it's picking this (via ifconfig):

gpd0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1400
        ether 02:50:41:00:01:01 
        inet 10.240.240.235 netmask 0xffffffff broadcast 10.240.240.235

I think get-ip strategy is broadly fine but the VPN is configured in a way which confuses it.

Some options to address this...

Option 1) Add :krell/server-ip option. Downside is it involves hard coding a value which can change in situations like moving from work to home wifi network.

Option 2) Prefer "most local" ip range. It seems 192.128... seems a safer bet than 10... so perhaps there is a logical precidence which could be applied.

Option 3) Some kind of test flight. Perhaps it's possible to verify the IP is sane before using it.

Option 4) Allow a blacklist/whitelist of network device names.

olivergeorge commented 4 years ago

I can't see better ways to differentiate the options based on this:

(clojure.pprint/pprint
  (for [ni (enumeration-seq (NetworkInterface/getNetworkInterfaces))
        :when (.isUp ni)
        ia (enumeration-seq (.getInetAddresses ni))
        :when (not (.isLinkLocalAddress ia))
        :when (not (.isLoopbackAddress ia))
        :when (instance? Inet4Address ia)]
    [(bean ni) (bean ia)]))
([{:MTU 1400,
   :interfaceAddresses
   [#object[java.net.InterfaceAddress 0x622ef26a "/10.240.240.235/32 [/10.240.240.235]"]],
   :loopback false,
   :parent nil,
   :index 14,
   :hardwareAddress [2, 80, 65, 0, 1, 1],
   :displayName "gpd0",
   :name "gpd0",
   :subInterfaces
   #object[java.net.NetworkInterface$1subIFs 0x7b02e036 "java.net.NetworkInterface$1subIFs@7b02e036"],
   :pointToPoint false,
   :up true,
   :class java.net.NetworkInterface,
   :virtual false,
   :inetAddresses
   #object[java.net.NetworkInterface$1checkedAddresses 0x85ec632 "java.net.NetworkInterface$1checkedAddresses@85ec632"]}
  {:MCOrgLocal false,
   :address [10, -16, -16, -21],
   :hostAddress "10.240.240.235",
   :canonicalHostName "myvpn-240-235.vpn.utas.edu.au",
   :anyLocalAddress false,
   :MCNodeLocal false,
   :hostName "myvpn-240-235.vpn.utas.edu.au",
   :MCLinkLocal false,
   :linkLocalAddress false,
   :loopbackAddress false,
   :MCSiteLocal false,
   :class java.net.Inet4Address,
   :MCGlobal false,
   :multicastAddress false,
   :siteLocalAddress true}]
 [{:MTU 1500,
   :interfaceAddresses
   [#object[java.net.InterfaceAddress 0x36b6964d "/fe80:0:0:0:cde:15ef:ea1d:996%en1/64 [null]"] #object[java.net.InterfaceAddress 0x438bad7c "/192.168.0.14/24 [/192.168.0.255]"]],
   :loopback false,
   :parent nil,
   :index 5,
   :hardwareAddress [20, 32, 94, 4, -28, -70],
   :displayName "en1",
   :name "en1",
   :subInterfaces
   #object[java.net.NetworkInterface$1subIFs 0x450794b4 "java.net.NetworkInterface$1subIFs@450794b4"],
   :pointToPoint false,
   :up true,
   :class java.net.NetworkInterface,
   :virtual false,
   :inetAddresses
   #object[java.net.NetworkInterface$1checkedAddresses 0x5710768a "java.net.NetworkInterface$1checkedAddresses@5710768a"]}
  {:MCOrgLocal false,
   :address [-64, -88, 0, 14],
   :hostAddress "192.168.0.14",
   :canonicalHostName "192.168.0.14",
   :anyLocalAddress false,
   :MCNodeLocal false,
   :hostName "192.168.0.14",
   :MCLinkLocal false,
   :linkLocalAddress false,
   :loopbackAddress false,
   :MCSiteLocal false,
   :class java.net.Inet4Address,
   :MCGlobal false,
   :multicastAddress false,
   :siteLocalAddress true}])
olivergeorge commented 4 years ago

Here's some sample code which might support Option 2. It would allow sorting by networkPrefixLength. (Not covinced this is a good idea)

(clojure.pprint/pprint
  (for [ni (enumeration-seq (NetworkInterface/getNetworkInterfaces))
        :when (.isUp ni)
        ifa (.getInterfaceAddresses ni)
        :let [ia (.getAddress ifa)]

        :when (not (.isLinkLocalAddress ia))
        :when (not (.isLoopbackAddress ia))
        :when (instance? Inet4Address ia)]
    {:host-address (.getHostAddress ia )
     :networkPrefixLength (.getNetworkPrefixLength ifa)}))
({:host-address "10.240.240.235", :networkPrefixLength 32}
 {:host-address "192.168.0.14", :networkPrefixLength 24})
olivergeorge commented 4 years ago

I'm closing this for now. I'm not able to substantiate the claimed issue.

mfikes commented 4 years ago

See #104