Skip to content

Commit 6fcc708

Browse files
committed
testing-integration-of-nat-tools-into-sdk
Signed-off-by: Robert Gogete <gogeterobert@yahoo.com>
1 parent 67b5191 commit 6fcc708

14 files changed

+3590
-0
lines changed

dig-node/.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
node_modules/
2+
dist/
3+
*.log
4+
.env
5+
.env.local
6+
.env.production
7+
.env.development
8+
dig-node-config.json
9+
coverage/
10+
.nyc_output/
11+
.vscode/settings.json
12+
*.tsbuildinfo

dig-node/README.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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
Binary file not shown.

dig-node/eslint.config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import js from "@eslint/js";
2+
import tseslint from "@typescript-eslint/eslint-plugin";
3+
import tsparser from "@typescript-eslint/parser";
4+
5+
export default [
6+
js.configs.recommended,
7+
{
8+
files: ["src/**/*.ts"],
9+
languageOptions: {
10+
parser: tsparser,
11+
parserOptions: {
12+
ecmaVersion: 2022,
13+
sourceType: "module"
14+
}
15+
},
16+
plugins: {
17+
"@typescript-eslint": tseslint
18+
},
19+
rules: {
20+
...tseslint.configs.recommended.rules,
21+
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
22+
"@typescript-eslint/explicit-function-return-type": "warn",
23+
"@typescript-eslint/no-explicit-any": "warn",
24+
"no-console": "off"
25+
}
26+
},
27+
{
28+
ignores: ["dist/**", "node_modules/**"]
29+
}
30+
];

0 commit comments

Comments
 (0)