Files
firezone/rust/connlib
Jamil 713c34e496 fix(connlib): Persist logging guard for the duration of the session (#2058)
This allows the file logger to write events as they're emitted so that
we (attempt to) capture everything for the lifetime of the session.

Sample:

```json
{"time":"2023-09-13T13:28:26.396615Z","target":"libs_common::session","logging.googleapis.com/sourceLocation":{"file":"connlib/libs/common/src/session.rs","line":"324"},"severity":"DEBUG","message":"Attempting connection to portal..."}
{"time":"2023-09-13T13:28:26.436317Z","target":"log","severity":"DEBUG","logFile":"/Users/jamil/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-0.21.7/src/client/hs.rs","logLine":73,"logModulePath":"rustls::client::hs","logTarget":"rustls::client::hs","message":"No cached session for DnsName(\"api.firez.one\")"}
{"time":"2023-09-13T13:28:26.43694Z","target":"log","severity":"DEBUG","logFile":"/Users/jamil/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-0.21.7/src/client/hs.rs","logLine":132,"logModulePath":"rustls::client::hs","logTarget":"rustls::client::hs","message":"Not resuming any session"}
{"time":"2023-09-13T13:28:26.446781Z","target":"log","severity":"DEBUG","logFile":"/Users/jamil/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-0.21.7/src/client/hs.rs","logLine":615,"logModulePath":"rustls::client::hs","logTarget":"rustls::client::hs","message":"Using ciphersuite TLS13_AES_256_GCM_SHA384"}
{"time":"2023-09-13T13:28:26.447046Z","target":"log","severity":"DEBUG","logFile":"/Users/jamil/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-0.21.7/src/client/tls13.rs","logLine":142,"logModulePath":"rustls::client::tls13","logTarget":"rustls::client::tls13","message":"Not resuming"}
{"time":"2023-09-13T13:28:26.449001Z","target":"log","severity":"DEBUG","logFile":"/Users/jamil/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-0.21.7/src/client/tls13.rs","logLine":381,"logModulePath":"rustls::client::tls13","logTarget":"rustls::client::tls13","message":"TLS1.3 encrypted extensions: []"}
{"time":"2023-09-13T13:28:26.449266Z","target":"log","severity":"DEBUG","logFile":"/Users/jamil/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-0.21.7/src/client/hs.rs","logLine":472,"logModulePath":"rustls::client::hs","logTarget":"rustls::client::hs","message":"ALPN protocol is None"}
{"time":"2023-09-13T13:28:26.544357Z","target":"libs_common::session","logging.googleapis.com/sourceLocation":{"file":"connlib/libs/common/src/session.rs","line":"327"},"severity":"WARNING","error":"PortalConnectionError(Http(Response { status: 404, version: HTTP/1.1, headers: {\"cache-control\": \"max-age=0, private, must-revalidate\", \"content-length\": \"9\", \"date\": \"Wed, 13 Sep 2023 13:28:25 GMT\", \"server\": \"Cowboy\", \"strict-transport-security\": \"max-age=63072000; includeSubDomains; preload\", \"x-request-id\": \"F4R4XmBOoVfqEVkAAAVh\", \"via\": \"1.1 google\", \"alt-svc\": \"h3=\\\":443\\\"; ma=2592000,h3-29=\\\":443\\\"; ma=2592000\", \"connection\": \"close\"}, body: Some([78, 111, 116, 32, 102, 111, 117, 110, 100]) }))","message":"Portal connection error"}
{"time":"2023-09-13T13:28:26.544838Z","target":"libs_common::session","logging.googleapis.com/sourceLocation":{"file":"connlib/libs/common/src/session.rs","line":"330"},"severity":"WARNING","message":"Error connecting to portal, retrying in 42 seconds"}
{"time":"2023-09-13T13:28:36.087416Z","target":"tunnel_state","logging.googleapis.com/sourceLocation":{"file":"connlib/libs/client/src/control.rs","line":"255"},"severity":"DEBUG","message":"TunnelStats {\n    public_key: \"BQCIkQ7iNdQxEnZo6lGwR8prKJgMlJGL+UPj+C50J0s=\",\n    peers_by_ip: {},\n    peer_connections: [\n        7482154e-107d-4981-8f5e-4becf1a9bfd2,\n    ],\n    resource_gateways: {\n        2a39fb5e-f7f4-44da-9163-5675c009a2ae: 7482154e-107d-4981-8f5e-4becf1a9bfd2,\n    },\n    dns_resources: {},\n    network_resources: {\n        V4(\n            Ipv4Network {\n                network_address: 172.31.83.10,\n                netmask: 32,\n            },\n        ): Cidr(\n            ResourceDescriptionCidr {\n                id: 01c6a1ea-2540-4ec8-9caa-0015ddfffb55,\n                address: V4(\n                    Ipv4Network {\n                        network_address: 172.31.83.10,\n                        netmask: 32,\n                    },\n                ),\n                name: \"TCP / UDPbin\",\n            },\n        ),\n        V4(\n            Ipv4Network {\n                network_address: 172.31.92.238,\n                netmask: 32,\n            },\n        ): Cidr(\n            ResourceDescriptionCidr {\n                id: 115ab626-ac3e-4890-b613-07f90bc1afb3,\n                address: V4(\n                    Ipv4Network {\n                        network_address: 172.31.92.238,\n                        netmask: 32,\n                    },\n                ),\n                name: \"Performance Testing\",\n            },\n        ),\n        V4(\n            Ipv4Network {\n                network_address: 172.31.82.179,\n                netmask: 32,\n            },\n        ): Cidr(\n            ResourceDescriptionCidr {\n                id: 2a39fb5e-f7f4-44da-9163-5675c009a2ae,\n                address: V4(\n                    Ipv4Network {\n                        network_address: 172.31.82.179,\n                        netmask: 32,\n                    },\n                ),\n                name: \"HTTPbin\",\n            },\n        ),\n        V4(\n            Ipv4Network {\n                network_address: 172.31.93.123,\n                netmask: 32,\n            },\n        ): Cidr(\n            ResourceDescriptionCidr {\n                id: 196b9f86-0789-4c2e-8afd-3b3cd59e1462,\n                address: V4(\n                    Ipv4Network {\n                        network_address: 172.31.93.123,\n                        netmask: 32,\n                    },\n                ),\n                name: \"IPerf3\",\n            },\n        ),\n    },\n    gateway_public_keys: {},\n    awaiting_connection: {\n        2a39fb5e-f7f4-44da-9163-5675c009a2ae: AwaitingConnectionDetails {\n            total_attemps: 31,\n            response_received: true,\n        },\n    },\n    gateway_awaiting_connection: {\n        7482154e-107d-4981-8f5e-4becf1a9bfd2: [],\n    },\n}"}
{"time":"2023-09-13T13:28:46.087297Z","target":"tunnel_state","logging.googleapis.com/sourceLocation":{"file":"connlib/libs/client/src/control.rs","line":"255"},"severity":"DEBUG","message":"TunnelStats {\n    public_key: \"BQCIkQ7iNdQxEnZo6lGwR8prKJgMlJGL+UPj+C50J0s=\",\n    peers_by_ip: {},\n    peer_connections: [\n        7482154e-107d-4981-8f5e-4becf1a9bfd2,\n    ],\n    resource_gateways: {\n        2a39fb5e-f7f4-44da-9163-5675c009a2ae: 7482154e-107d-4981-8f5e-4becf1a9bfd2,\n    },\n    dns_resources: {},\n    network_resources: {\n        V4(\n            Ipv4Network {\n                network_address: 172.31.82.179,\n                netmask: 32,\n            },\n        ): Cidr(\n            ResourceDescriptionCidr {\n                id: 2a39fb5e-f7f4-44da-9163-5675c009a2ae,\n                address: V4(\n                    Ipv4Network {\n                        network_address: 172.31.82.179,\n                        netmask: 32,\n                    },\n                ),\n                name: \"HTTPbin\",\n            },\n        ),\n        V4(\n            Ipv4Network {\n                network_address: 172.31.83.10,\n                netmask: 32,\n            },\n        ): Cidr(\n            ResourceDescriptionCidr {\n                id: 01c6a1ea-2540-4ec8-9caa-0015ddfffb55,\n                address: V4(\n                    Ipv4Network {\n                        network_address: 172.31.83.10,\n                        netmask: 32,\n                    },\n                ),\n                name: \"TCP / UDPbin\",\n            },\n        ),\n        V4(\n            Ipv4Network {\n                network_address: 172.31.92.238,\n                netmask: 32,\n            },\n        ): Cidr(\n            ResourceDescriptionCidr {\n                id: 115ab626-ac3e-4890-b613-07f90bc1afb3,\n                address: V4(\n                    Ipv4Network {\n                        network_address: 172.31.92.238,\n                        netmask: 32,\n                    },\n                ),\n                name: \"Performance Testing\",\n            },\n        ),\n        V4(\n            Ipv4Network {\n                network_address: 172.31.93.123,\n                netmask: 32,\n            },\n        ): Cidr(\n            ResourceDescriptionCidr {\n                id: 196b9f86-0789-4c2e-8afd-3b3cd59e1462,\n                address: V4(\n                    Ipv4Network {\n                        network_address: 172.31.93.123,\n                        netmask: 32,\n                    },\n                ),\n                name: \"IPerf3\",\n            },\n        ),\n    },\n    gateway_public_keys: {},\n    awaiting_connection: {\n        2a39fb5e-f7f4-44da-9163-5675c009a2ae: AwaitingConnectionDetails {\n            total_attemps: 31,\n            response_received: true,\n        },\n    },\n    gateway_awaiting_connection: {\n        7482154e-107d-4981-8f5e-4becf1a9bfd2: [],\n    },\n}"}
{"time":"2023-09-13T13:28:53.703612Z","target":"log","severity":"WARNING","logFile":"/Users/jamil/.cargo/git/checkouts/webrtc-316f277f555c12ed/672e728/mdns/src/conn/mod.rs","logLine":359,"logModulePath":"webrtc_mdns::conn","logTarget":"webrtc_mdns::conn","message":"Failed to parse mDNS packet parsing/packing of this type isn't available yet"}
{"time":"2023-09-13T13:28:54.709612Z","target":"log","severity":"WARNING","logFile":"/Users/jamil/.cargo/git/checkouts/webrtc-316f277f555c12ed/672e728/mdns/src/conn/mod.rs","logLine":359,"logModulePath":"webrtc_mdns::conn","logTarget":"webrtc_mdns::conn","message":"Failed to parse mDNS packet parsing/packing of this type isn't available yet"}
{"time":"2023-09-13T13:28:56.086942Z","target":"tunnel_state","logging.googleapis.com/sourceLocation":{"file":"connlib/libs/client/src/control.rs","line":"255"},"severity":"DEBUG","message":"TunnelStats {\n    public_key: \"BQCIkQ7iNdQxEnZo6lGwR8prKJgMlJGL+UPj+C50J0s=\",\n    peers_by_ip: {},\n    peer_connections: [\n        7482154e-107d-4981-8f5e-4becf1a9bfd2,\n    ],\n    resource_gateways: {\n        2a39fb5e-f7f4-44da-9163-5675c009a2ae: 7482154e-107d-4981-8f5e-4becf1a9bfd2,\n    },\n    dns_resources: {},\n    network_resources: {\n        V4(\n            Ipv4Network {\n                network_address: 172.31.82.179,\n                netmask: 32,\n            },\n        ): Cidr(\n            ResourceDescriptionCidr {\n                id: 2a39fb5e-f7f4-44da-9163-5675c009a2ae,\n                address: V4(\n                    Ipv4Network {\n                        network_address: 172.31.82.179,\n                        netmask: 32,\n                    },\n                ),\n                name: \"HTTPbin\",\n            },\n        ),\n        V4(\n            Ipv4Network {\n                network_address: 172.31.93.123,\n                netmask: 32,\n            },\n        ): Cidr(\n            ResourceDescriptionCidr {\n                id: 196b9f86-0789-4c2e-8afd-3b3cd59e1462,\n                address: V4(\n                    Ipv4Network {\n                        network_address: 172.31.93.123,\n                        netmask: 32,\n                    },\n                ),\n                name: \"IPerf3\",\n            },\n        ),\n        V4(\n            Ipv4Network {\n                network_address: 172.31.83.10,\n                netmask: 32,\n            },\n        ): Cidr(\n            ResourceDescriptionCidr {\n                id: 01c6a1ea-2540-4ec8-9caa-0015ddfffb55,\n                address: V4(\n                    Ipv4Network {\n                        network_address: 172.31.83.10,\n                        netmask: 32,\n                    },\n                ),\n                name: \"TCP / UDPbin\",\n            },\n        ),\n        V4(\n            Ipv4Network {\n                network_address: 172.31.92.238,\n                netmask: 32,\n            },\n        ): Cidr(\n            ResourceDescriptionCidr {\n                id: 115ab626-ac3e-4890-b613-07f90bc1afb3,\n                address: V4(\n                    Ipv4Network {\n                        network_address: 172.31.92.238,\n                        netmask: 32,\n                    },\n                ),\n                name: \"Performance Testing\",\n            },\n        ),\n    },\n    gateway_public_keys: {},\n    awaiting_connection: {\n        2a39fb5e-f7f4-44da-9163-5675c009a2ae: AwaitingConnectionDetails {\n            total_attemps: 31,\n            response_received: true,\n        },\n    },\n    gateway_awaiting_connection: {\n        7482154e-107d-4981-8f5e-4becf1a9bfd2: [],\n    },\n}"}
{"time":"2023-09-13T13:28:57.52105Z","target":"firezone_tunnel::tun","logging.googleapis.com/sourceLocation":{"file":"connlib/libs/tunnel/src/tun_darwin.rs","line":"224"},"severity":"DEBUG","message":"MTU for utun7 is 1420"}
```


Sample log attached:


[connlib.log.zip](https://github.com/firezone/firezone/files/12598066/connlib.log.zip)
2023-09-20 17:21:09 +00:00
..
2023-07-03 18:48:55 +00:00

Connlib

Firezone's connectivity library shared by all clients.

🚧 Disclaimer 🚧

NOTE: This repository is undergoing heavy construction. You could say we're Building In The Open™ in true open source spirit. Do not attempt to use anything released here until this notice is removed. You have been warned.

Building Connlib

Setting the CONNLIB_MOCK environment variable when packaging for Apple or Android will activate the mock feature flag, replacing connlib's normal connection logic with a mock for testing purposes.

  1. You'll need a Rust toolchain installed if you don't have one already. We recommend following the instructions at https://rustup.rs.
  2. rustup show will install all needed targets since they are added to rust-toolchain.toml.
  3. Follow the relevant instructions for your platform:
  4. Apple
  5. Android
  6. Linux
  7. Windows

Apple

Connlib should build successfully with recent macOS and Xcode versions assuming you have Rust installed. If not, open a PR with the notes you found.

Android

Linux

Windows