Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

9 Commits

Repository files navigation

NGHOST

NGHOST is a LAN-first peer-assisted file downloader written in Go.

It allows machines on the same local network to automatically share already-downloaded files with each other, reducing repeated internet downloads and improving download speeds on shared networks such as:

  • college Wi-Fi
  • hostels
  • labs
  • offices
  • maker spaces

Instead of every machine downloading the same file separately from the internet, NGHOST checks whether another peer on the LAN already has the file and downloads it locally.


Infrastructure

Infrastructure image


Video Demo (using two devices on one LAN)

asciicast


How It Works

LAN-First Download Flow

When downloading a file:

  1. The client downloads only the first 1 MB from the internet

  2. A SHA256 hash of that chunk is computed

  3. The LAN is scanned using mDNS for NGHOST peers

  4. Each peer is queried:

    • “Do you have a file matching this hash?”
  5. If a peer has the file:

    • the full file is downloaded over LAN
  6. Otherwise:

    • download falls back to the internet

This dramatically reduces WAN bandwidth usage when many users download the same files.


Features

  • LAN peer discovery using mDNS
  • SHA256 content-addressable lookup
  • Partial-hash matching using first 1 MB
  • SQLite-based file index
  • Automatic directory scanning
  • HTTP-based file serving
  • Internet fallback when LAN misses
  • Resume support for servers with HTTP Range requests
  • Zero central server required

Architecture

Daemon

The daemon:

  • scans a shared directory
  • computes hashes
  • stores metadata in SQLite
  • advertises itself over mDNS
  • serves files over HTTP

Endpoints:

  • /has/<full_sha256>
  • /hasfirst/<first1mb_sha256>

Client

The client:

  • discovers peers over mDNS
  • checks LAN availability
  • downloads from peers when possible
  • falls back to internet when needed

Project Structure

nghost/
├── client/
│ └── main.go (client code)
├── daemon/
│ ├── main.go (daemon code should be run on background with systemctl)
│ ├── conf.json │ └── files.db (generated by the daemon at runtime)
├── go.mod
└── go.sum

Installation

Requirements

  • Go 1.22+
  • SQLite3

Clone

git clone https://github.com/lsnnt/nghost.git
cd nghost
go mod tidy

Build

Daemon

go build -o daemon ./daemon

Client

go build -o client ./client

Configuration

Create conf.json inside daemon/:

{
"DDir": ["/path/to/shared/files"]
}

Running

Start Daemon

cd daemon
./daemon

Make sure conf.json is in same folder as daemon The daemon will:

  • start HTTP server on port 14920 (normal ports may be occupied so)
  • advertise itself via mDNS
  • scan files every 30 seconds

Download by URL

./client -url https://example.com/file.iso

Download by Full SHA256

./client -hash <sha256>

Custom Output File

./client -url https://example.com/file.iso -o ubuntu.iso

Example Workflow

Student A downloads:

ubuntu-24.04.iso

The daemon indexes the file and advertises availability on the LAN.

Later, Student B runs:

./client -url https://releases.ubuntu.com/ubuntu-24.04.iso

Instead of downloading from the internet again, the file is transferred directly over the LAN.


Security

NGHOST is designed for trusted local networks and cooperative file sharing.

Current implementation:

  • no authentication
  • no encryption
  • no access control

Do not expose the daemon directly to the public internet.


Why?

Shared networks often suffer from repeated downloads of identical large files:

  • Linux ISOs
  • datasets
  • game installers
  • lecture videos
  • development tools

NGHOST reduces redundant internet traffic by turning the LAN itself into a cooperative cache.


Limitations

This is a LAN project so it will only work if some other user in the same LAN is running the daemon and they have the file avaliable otherwise it will work as a normal downloader.

Ai Disclosure

This code is Ai-Assisted but if you cannot understand any function just contact me.

Inspiration

Idea and inspiration from : https://github.com/PurviMalhotra/Ghost

About

a LAN-aware cooperative caching system that reuse downloaded assets locally, reducing internet bandwidth usage through peer discovery and cache sharing.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages