static TNLNetworkReachabilityFlags _NetworkReachabilityFlagsFromPath()

in Source/TNLCommunicationAgent.m [888:943]


static TNLNetworkReachabilityFlags _NetworkReachabilityFlagsFromPath(nw_path_t path)
{
    if (tnl_available_ios_12) {
        TNLNetworkReachabilityMask flags = 0;
        if (path != nil) {
            const nw_path_status_t status = nw_path_get_status(path);
            if (status > 0) {
#if DEBUG
                if (gTwitterNetworkLayerAssertEnabled) {
                    switch (status) {
                        case nw_path_status_invalid:
                        case nw_path_status_satisfied:
                        case nw_path_status_unsatisfied:
                        case nw_path_status_satisfiable:
                            break;
                        default:
                            TNLAssertMessage(0, @"the nw_path_status_t enum has expanded!  Need to update TNLNetworkReachabilityMask.");
                            break;
                    }
                }
#endif
                flags |= _NWPathStatusToFlag(status);
            }

            for (nw_interface_type_t itype = 0; itype <= 4; itype++) {
                const bool usesInterface = nw_path_uses_interface_type(path, itype);
                if (usesInterface) {
                    flags |= _NWInterfaceTypeToFlag(itype);
                }
            }

#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST || TARGET_OS_OSX
            // When run on macOS (however the avenue) we will coerce
            // to have an ethernet connection when we detect `Other` but no actual interface.
            // This is most commonly due to VPN connections "hiding" the physical interface on Macs.
            if (TNL_BITMASK_INTERSECTS_FLAGS(flags, TNLNetworkReachabilityMaskPathIntefaceTypeOther)) {
                if (TNL_BITMASK_EXCLUDES_FLAGS(flags, TNLNetworkReachabilityMaskPathIntefaceTypeWifi | TNLNetworkReachabilityMaskPathIntefaceTypeCellular | TNLNetworkReachabilityMaskPathIntefaceTypeWired)) {
                    flags |= TNLNetworkReachabilityMaskPathIntefaceTypeWifi;
                }
            }
#endif

            if (tnl_available_ios_13) {
                if (nw_path_is_expensive(path)) {
                    flags |= TNLNetworkReachabilityMaskPathConditionExpensive;
                }
                if (nw_path_is_constrained(path)) {
                    flags |= TNLNetworkReachabilityMaskPathConditionConstrained;
                }
            }
        }
        return flags;
    }

    return 0;
}