|
| 1 | +# DIG Node |
| 2 | + |
| 3 | +A CLI application for participating in the DIG network file sharing system. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🔄 Automatically scans and shares .dig files from ~/.dig directory |
| 8 | +- 🌐 Peer discovery and communication via GunJS |
| 9 | +- 📥 Automatic download of missing .dig files from other nodes |
| 10 | +- 🚀 Built on dig-nat-tools for NAT traversal and P2P connectivity |
| 11 | +- 📝 Comprehensive logging and configuration options |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +1. Navigate to the dig-node directory: |
| 16 | + ```bash |
| 17 | + cd dig-node |
| 18 | + ``` |
| 19 | + |
| 20 | +2. Install dependencies: |
| 21 | + ```bash |
| 22 | + npm install |
| 23 | + ``` |
| 24 | + |
| 25 | +3. Build the project: |
| 26 | + ```bash |
| 27 | + npm run build |
| 28 | + ``` |
| 29 | + |
| 30 | +4. (Optional) Link globally for system-wide access: |
| 31 | + ```bash |
| 32 | + npm link |
| 33 | + ``` |
| 34 | + |
| 35 | +## Usage |
| 36 | + |
| 37 | +### Start a node |
| 38 | +```bash |
| 39 | +dig-node start |
| 40 | +``` |
| 41 | + |
| 42 | +### Start with custom options |
| 43 | +```bash |
| 44 | +dig-node start --port 9090 --dig-dir ./my-dig-files --log-level debug |
| 45 | +``` |
| 46 | + |
| 47 | +### Generate a configuration file |
| 48 | +```bash |
| 49 | +dig-node config --output my-config.json |
| 50 | +``` |
| 51 | + |
| 52 | +### Start with configuration file |
| 53 | +```bash |
| 54 | +dig-node start --config my-config.json |
| 55 | +``` |
| 56 | + |
| 57 | +## Configuration |
| 58 | + |
| 59 | +### Command Line Options |
| 60 | + |
| 61 | +- `--port <port>`: Port to listen on (default: 8080) |
| 62 | +- `--dig-dir <path>`: Directory containing .dig files (default: ~/.dig) |
| 63 | +- `--peers <peers>`: Comma-separated list of GunJS peers |
| 64 | +- `--namespace <namespace>`: GunJS namespace (default: dig-network) |
| 65 | +- `--log-level <level>`: Log level (debug, info, warn, error, default: info) |
| 66 | +- `--config <path>`: Path to configuration file |
| 67 | + |
| 68 | +### Configuration File Format |
| 69 | + |
| 70 | +```json |
| 71 | +{ |
| 72 | + "port": 8080, |
| 73 | + "digDirectory": "/home/user/.dig", |
| 74 | + "gunOptions": { |
| 75 | + "peers": ["http://nostalgiagame.go.ro:30878/gun"], |
| 76 | + "namespace": "dig-network", |
| 77 | + "webrtc": { |
| 78 | + "iceServers": [ |
| 79 | + { "urls": "stun:stun.l.google.com:19302" }, |
| 80 | + { "urls": "stun:stun1.l.google.com:19302" } |
| 81 | + ] |
| 82 | + } |
| 83 | + }, |
| 84 | + "logLevel": "info", |
| 85 | + "syncInterval": 30000, |
| 86 | + "maxConcurrentDownloads": 5 |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +## Architecture |
| 91 | + |
| 92 | +The DIG Node consists of several key components: |
| 93 | + |
| 94 | +### DigNode (Main Controller) |
| 95 | +- Coordinates all components |
| 96 | +- Handles graceful startup and shutdown |
| 97 | +- Manages periodic sync operations |
| 98 | + |
| 99 | +### FileManager |
| 100 | +- Monitors the .dig directory for changes |
| 101 | +- Calculates SHA256 hashes for files |
| 102 | +- Emits events when files are added/removed |
| 103 | + |
| 104 | +### NetworkManager |
| 105 | +- Integrates with dig-nat-tools for P2P connectivity |
| 106 | +- Handles peer discovery via GunJS |
| 107 | +- Manages file announcements and downloads |
| 108 | + |
| 109 | +### Logger |
| 110 | +- Provides structured logging with multiple levels |
| 111 | +- Color-coded output for better readability |
| 112 | + |
| 113 | +## Development |
| 114 | + |
| 115 | +### Watch mode for development |
| 116 | +```bash |
| 117 | +npm run dev |
| 118 | +``` |
| 119 | + |
| 120 | +### Lint code |
| 121 | +```bash |
| 122 | +npm run lint |
| 123 | +``` |
| 124 | + |
| 125 | +### Fix linting issues |
| 126 | +```bash |
| 127 | +npm run lint:fix |
| 128 | +``` |
| 129 | + |
| 130 | +## Integration with dig-nat-tools |
| 131 | + |
| 132 | +This project uses the compiled version of dig-nat-tools from the parent directory's `dist` folder. The integration includes: |
| 133 | + |
| 134 | +- **FileHost**: For serving .dig files to other peers |
| 135 | +- **FileClient**: For downloading files from remote peers |
| 136 | +- **GunRegistry**: For peer discovery and network coordination |
| 137 | +- **Connection modes**: Support for direct HTTP and WebTorrent transfers |
| 138 | + |
| 139 | +## File Discovery Process |
| 140 | + |
| 141 | +1. **Local Scanning**: On startup, scan ~/.dig for all .dig files |
| 142 | +2. **Hash Calculation**: Calculate SHA256 hash for each file |
| 143 | +3. **Announcement**: Announce available files to the GunJS network |
| 144 | +4. **Peer Discovery**: Listen for other nodes announcing their files |
| 145 | +5. **Download**: Automatically download missing .dig files |
| 146 | +6. **Monitoring**: Watch for new files and announce them |
| 147 | + |
| 148 | +## TODO |
| 149 | + |
| 150 | +- [ ] Complete integration with dig-nat-tools components |
| 151 | +- [ ] Implement file announcement protocol |
| 152 | +- [ ] Add WebTorrent support for large file transfers |
| 153 | +- [ ] Implement proper peer file listing |
| 154 | +- [ ] Add configuration validation |
| 155 | +- [ ] Add status monitoring dashboard |
| 156 | +- [ ] Implement daemon mode |
| 157 | +- [ ] Add automatic restart on crashes |
| 158 | +- [ ] Add bandwidth limiting options |
| 159 | +- [ ] Implement file prioritization system |
0 commit comments