The LANCache utility is automatically deployed with all Addigy agents and helps distribute files and packages across the local area network (LAN). This helps reduce the amount of internet bandwidth used when downloading software to devices on the same LAN.
When a LANCache device needs to download a file to complete a command from Addigy, the first thing it will do is determine which peer to use. LANCache devices have a weighting set and the agent will check with the highest-weighted device on the network to see if it has the needed file.
If the highest-weighted device does not have the file it needs, it will check other LANCache devices (aka peers) on the same local subnet to see if it can find the file. If the file is not available within the subnet, it will download it from the source (e.g. download the file over the internet).
Once device has downloaded a file with LANCache, that file is added to the LANCache index so other devices will know it is available to download from that device. So, if a device already recently downloaded a file and it's still has a copy that device), when the device checks the LANCache index, it will see that it already has it and just use its own copy.
Using LANCache
The following command will display the parameters available for managing the Addigy LANCache utility:
/Library/Addigy/lan-cache ?
Output:
-md5 string Tells the cache client to check the check the downloaded file's md5 hash againt the md5 hash provided. If it fails, the file will be rejected. This option only works with the download action. -peer-proxy Sets the device to act as a proxy for his peers. Values should be either true or false. Enabling this setting will mean that this device will always serve the files requested even if it is not currently in its cache. In case where the file is not in its cache, the file will be fetched from the public web resource, cached locally, and served to its peer. -set-default-settings Resets the lan-cache settings to its default values. -set-peer-proxy-setting Indicates that you are trying enable or disable the peer-proxy setting. The value from the peer-proxy option will be used. -set-weight-setting Indicates that you are trying set the weight setting. The value from the weight option will be used. -v Prints the current version. -weight int Sets the peer weight for this device. The weight can be any integer. The weight influences the likelihood of a device to get polled by other devices in the network. Peers will be checked in decreasing weight order. This means that a device with a weight of 2 will be polled for files before a device with a weight of 1. Devices have a weight of 1 by default. Actions: download web_url local_path Downloads the file specified by web_url to the local_path. peers Outputs a json formatted list of the current peers from the device. host Starts the lan-cache server.
Advanced LANCache Command Examples
To prioritize a device as a LANCache host, use this command to set the weight of a device to 100.
Note: Setting a higher weight on an Addigy Agent prioritizes that device higher as the lan-cache. Devices with lower weight will have less prioritization as the lan-cache. More information on this can be found in Additional Notes - LANCache Weight.
/Library/Addigy/lan-cache -set-weight-setting -weight=100
After changing the weight, relaunch the LANCache server to have it pick up the new weight setting.
sudo launchctl unload /Library/LaunchDaemons/com.addigy.lan-cache.plist && sudo launchctl load /Library/LaunchDaemons/com.addigy.lan-cache.plist
To see what peers are visible to a device on the subnet using LANCache, run this command.
/Library/Addigy/lan-cache peers
To set a device as a download proxy server, run this command. "Proxy" devices will download on behalf of other devices and then serve them the file using LANCache.
/Library/Addigy/lan-cache -peer-proxy -set-peer-proxy-setting
Best Practices
Ideally, customizing the LANCache settings in your network will include both a peer proxy and weight setting to designate a specific machine as a caching server. This implies that all files will be downloaded from a specific server before distributed to other devices within the environment.
If only the 'weight' setting is implemented, devices will attempt to fetch from the higher weighted peer before checking other peers and/or downloading from the internet.
Choosing the right LANCache method is really dependent on your network configuration(s), and what is ideal for your environment.
Additional Notes
- Logs are stored in /Library/Addigy/logs/cache.log
- Downloaded files from LANCache are stored in /Library/Addigy/download-cache/downloaded (We have a Community Script called 'Purge Addigy Cache' available)
- LANCache runs on port 64084 on all devices (https://localhost:64084)
- LANCache uses DNS Service Discovery (aka mDNS or Bonjour) to identify peers
- To use LANCache to download files, see our article Creating Custom Software with Large Files
- LANCache uses an SSL certificate for certificate pinning when downloading and validating files
- LANCache uses a MD5 hash algorithm to validate software before distribution
- LANCache uses a SQLite3 database to store downloaded records on the device
LANCache Weight
- LANCache weight will dictate which specific Addigy Agent will be the primary LANCache server. This means Addigy agents with higher weight will have more priority when serving files. For example, you may want to set a file server with the weight of 100 so other Addigy agents always try to fetch files from that device first. Important desktops or laptops with smaller storage capacity should be set to 0 so they aren't targeted as a primary LANCache device.
- If you always want a specific device to serve files, you should use the `-peer-proxy -set-peer-proxy-setting`, which will force the agents to download files specifically from that file server.