github.com/status-im/status-go@v1.1.0/server/pairing/TODO.MD (about) 1 # Local Pairing To-dos 2 3 - [Network Address / Peer Discovery](#network-address--peer-discovery) 4 - [Network Debug Diagnostics](#network-debug-diagnostics) 5 6 ## Network Address / Peer Discovery 7 8 Revamp the preferred network discovery process 9 10 Note this functionality is pre-secret share so doesn't ... 11 12 - **Pre-shared secret: scan the QR code first, containing the secret and then attempt to discover the other device(s)** 13 - ⚠️ **Problem:** Only works if UDP discovery works. [See possible solution for UDP discovery failure mitigation](#udp-discovery-failure-mitigation) 14 - Start pairing server on relevant device, listen to `0.0.0.0`. 15 - get selected port number 16 - get TLS pub key 17 - get secret 18 - Scan QR code which including: 19 - selected port number 20 - TLS pub key 21 - secret 22 - UDP discovery happens 🧙🪄✨ 23 - devices acquire ip addresses of peer(s), and themselves. 24 - client device attempts connection as normal 25 - **Post-shared secret, which is confirmed later with the QR code** 26 - UDP discovery happens 🧙🪄✨ 27 - devices acquire ip addresses of peer(s), and themselves. 28 - can also optionally give feedback to the user with the pairing options. 29 - server device starts server listener, listen to known network ip address 30 - get selected port number 31 - get TLS pub key 32 - get secret 33 - Scan QR code which including: 34 - selected port number 35 - TLS pub key 36 - secret 37 - client device attempts connection as normal 38 39 ### Self IP address acquisition 40 41 1. Ask network interface for its preferred outbound IP address 42 - The process currently relied on 43 - Add a required a self "confirmation" ping, to ensure the given address is network addressable. 44 - On fail, fall through to stage 2 45 2. device gets a list of its network addresses. 46 - Use `netIfaces, err := net.Interfaces()` [See snippet](#get-all-network-addresses) 47 - run filter for only local private net addrs 48 - open listener on 0.0.0.0 49 - make an outbound network call to all ips 50 - call should include the addressing ip so device knows which address is network addressable 51 - record all ip addresses that are able to ping the listener. 52 - hopefully the list will only ever contain 1 IP address 53 - On fail, fall through to stage 3 54 3. Attempt discovery via UDP multicast 55 - **Question :** How do **both** devices know when to start UDP discovery? 56 - Perhaps the QR code device can add details to the application 57 - no guarantee that both devices get an IP address 58 - [See UDP discovery failure mitigation](#udp-discovery-failure-mitigation) 59 60 ## Network Debug Diagnostics 61 62 We need to check a few things if a connection isn't working 63 64 - What network ip address does the device think it has? 65 - What is the port number the listener is listening on? 66 - Can the device access its own network IP address? 67 - Can a device find, and be found by, other devices? 68 - attempt UDP discovery 69 - What is the device's network connection(s) status? 70 - `ipconfig` / `ifconfig` 71 - Test each in series, all above functions 72 - Capture everything, even errors 73 - DO NOT early return errors, log the errors, proceed with the next function. 74 - log all outputs to standard logger 75 - log all outputs memory for export / return 76 - When test suite is complete return log out put 77 78 ## Refs 79 80 ###### UDP discovery failure mitigation 81 82 - Both devices listen on a tcp port chosen by the network interface 83 - Attempt UDP discovery 84 - In the UDP packet include: 85 - the device's listener port number 86 - ensure the notifier's id is stored for later connections via tcp 87 - When peer A discovers peer B, peer A pings peer B's "confirmation" listener with peer B's IP address and network info about peer A 88 - peer B attempts an outbound **TLS** connection to its own "confirmation" server, with a random code, to confirm its own IP address. 89 90 91 ###### Get all network addresses 92 93 ```go 94 package test 95 96 import ( 97 "fmt" 98 "net" 99 ) 100 101 func AllNetworkAddresses() error { 102 netIfaces, err := net.Interfaces() 103 if err != nil { 104 return err 105 } 106 107 for _, i := range netIfaces { 108 addrs, err := i.Addrs() 109 if err != nil { 110 return err 111 } 112 113 for _, addr := range addrs { 114 var ip net.IP 115 switch v := addr.(type) { 116 case *net.IPNet: 117 ip = v.IP 118 case *net.IPAddr: 119 ip = v.IP 120 default: 121 return fmt.Errorf("unknown ip type %s", v) 122 } 123 fmt.Print(ip) 124 } 125 } 126 return nil 127 } 128 ```