Skip to content

Commit 3a5f234

Browse files
authored
Merge pull request #10 from hcp-uw/tapestry
Tapestry
2 parents 4e01f7d + f0c72b8 commit 3a5f234

39 files changed

Lines changed: 983 additions & 79 deletions

cmd/mosaic-node/main.go

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,17 @@
11
package main
22

33
import (
4-
54
"fmt"
6-
//"os"
75

86
//"github.com/hcp-uw/mosaic/internal/cli"
97
"github.com/hcp-uw/mosaic/internal/daemon"
108
)
119

1210
func main() {
13-
//if len(os.Args) > 1 {
14-
// cli.Run(os.Args)
15-
// return
16-
//}
11+
1712
if err := daemon.StartServer(); err != nil {
1813
panic(err)
1914
}
20-
fmt.Println("welcome to mosaic")
21-
22-
23-
file, err := os.ReadFile("output_file.jpg")
24-
if err != nil {
25-
log.Fatal(err)
26-
}
27-
28-
fileSize := len(file)
29-
30-
encoder, err := encoding.NewEncoder(8, 4, "./files", "./files/.bin")
31-
32-
if err != nil {
33-
log.Fatal(err)
34-
}
35-
36-
//err = encoder.EncodeFile("/pictures/pic.jpg")
37-
//if err != nil {
38-
// fmt.Println(err)
39-
//}
40-
41-
//fmt.Println(fileSize)
42-
43-
err = encoder.DecodeShards("pictures/pic.jpg", fileSize)
44-
if err != nil {
45-
log.Fatal(err)
46-
}
47-
4815

16+
fmt.Println("welcome to mosaic")
4917
}

cmd/mosaic-stun/main.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"log"
7+
"os"
8+
"os/signal"
9+
"syscall"
10+
11+
"github.com/hcp-uw/mosaic/internal/stun"
12+
)
13+
14+
func main() {
15+
port := flag.String("port", "3478", "Port to listen on (server mode)")
16+
17+
runServer(*port)
18+
}
19+
20+
func runServer(port string) {
21+
config := &stun.ServerConfig{
22+
ListenAddress: ":" + port,
23+
ClientTimeout: 30 * 1000000000, // 30 seconds in nanoseconds
24+
PingInterval: 10 * 1000000000, // 10 seconds in nanoseconds
25+
MaxQueueSize: 100,
26+
EnableLogging: true,
27+
}
28+
29+
server := stun.NewServer(config)
30+
31+
if err := server.Start(config); err != nil {
32+
log.Fatalf("Failed to start server: %v", err)
33+
}
34+
35+
fmt.Printf("STUN server running on port %s\n", port)
36+
fmt.Println("Press Ctrl+C to stop")
37+
38+
// Wait for interrupt signal
39+
sigChan := make(chan os.Signal, 1)
40+
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
41+
<-sigChan
42+
43+
fmt.Println("\nShutting down server...")
44+
server.Stop()
45+
}
46+

internal/cli/CLI.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"syscall"
1111

1212
"github.com/hcp-uw/mosaic/internal/cli/client"
13-
"github.com/hcp-uw/mosaic/internal/cli/handlers/helpers"
1413
"github.com/hcp-uw/mosaic/internal/cli/protocol"
14+
"github.com/hcp-uw/mosaic/internal/daemon/handlers/helpers"
1515
)
1616

1717
//go:embed HelpMessage.txt
@@ -64,15 +64,15 @@ func Run(Args []string) {
6464
}
6565
version()
6666
case "join":
67-
if len(args) != 3 {
67+
if len(args) != 4 {
6868
fmt.Println()
6969
fmt.Println("Usage:")
70-
fmt.Println("- mos join network Join the network.")
70+
fmt.Println("- mos join network <Server address to connect to (e.g., 127.0.0.1:3478)> Join the network.")
7171
os.Exit(1)
7272
}
7373
switch args[2] {
7474
case "network":
75-
joinNetwork()
75+
joinNetwork(args[3])
7676
default:
7777
fmt.Println("Unknown argument:", args[2])
7878
os.Exit(1)
@@ -255,15 +255,15 @@ func Run(Args []string) {
255255
}
256256

257257
// Connects the user to the mosaic network
258-
func joinNetwork() {
259-
resp, err := client.SendRequest("joinNetwork", protocol.JoinRequest{})
258+
func joinNetwork(serverAddr string) {
259+
resp, err := client.SendRequest("joinNetwork", protocol.JoinRequest{ServerAddress: serverAddr})
260260
exitOnErr(err, "Error joining network.")
261261

262262
var cmdResp protocol.JoinResponse
263263
if err := mapToStruct(resp.Data, &cmdResp); err != nil {
264264
exitOnErr(err, "Error parsing response.")
265265
}
266-
message := fmt.Sprintf("\nJoined network successfully.\n- Connected to %d peers.\n", cmdResp.Peers)
266+
message := fmt.Sprintf("\nJoined network successfully.\n- Connected to %d peers.\n")
267267
fmt.Println(message)
268268
}
269269

internal/cli/handlers/joinNetwork.go

Lines changed: 0 additions & 20 deletions
This file was deleted.

internal/cli/protocol/protocol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ type NetworkStatusResponse struct {
4747
}
4848

4949
type JoinRequest struct {
50+
ServerAddress string `json:"ServerAddress"`
5051
}
5152

5253
type JoinResponse struct {
5354
Success bool `json:"success"`
5455
Details string `json:"details"`
55-
Peers int `json:"peers"`
5656
}
5757

5858
type NodeStatusRequest struct {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package handlers
33
import (
44
"fmt"
55

6-
"github.com/hcp-uw/mosaic/internal/cli/handlers/helpers"
76
"github.com/hcp-uw/mosaic/internal/cli/protocol"
7+
"github.com/hcp-uw/mosaic/internal/daemon/handlers/helpers"
88
)
99

1010
// Deletes a file from the network and returns an DeleteFileResponse
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package handlers
33
import (
44
"fmt"
55

6-
"github.com/hcp-uw/mosaic/internal/cli/handlers/helpers"
76
"github.com/hcp-uw/mosaic/internal/cli/protocol"
7+
"github.com/hcp-uw/mosaic/internal/daemon/handlers/helpers"
88
)
99

1010
// Deletes a file from the network and returns an DeleteFolderResponse
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package handlers
33
import (
44
"fmt"
55

6-
"github.com/hcp-uw/mosaic/internal/cli/handlers/helpers"
76
"github.com/hcp-uw/mosaic/internal/cli/protocol"
7+
"github.com/hcp-uw/mosaic/internal/daemon/handlers/helpers"
88
)
99

1010
// Deletes a file from the network and returns an DeleteFileResponse

internal/cli/handlers/downloadFolder.go renamed to internal/daemon/handlers/downloadFolder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package handlers
33
import (
44
"fmt"
55

6-
"github.com/hcp-uw/mosaic/internal/cli/handlers/helpers"
76
"github.com/hcp-uw/mosaic/internal/cli/protocol"
7+
"github.com/hcp-uw/mosaic/internal/daemon/handlers/helpers"
88
)
99

1010
// Deletes a file from the network and returns an DownloadFolderResponse
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package handlers
33
import (
44
"fmt"
55

6-
"github.com/hcp-uw/mosaic/internal/cli/handlers/helpers"
76
"github.com/hcp-uw/mosaic/internal/cli/protocol"
7+
"github.com/hcp-uw/mosaic/internal/daemon/handlers/helpers"
88
)
99

1010
// Deletes all user data and returns a EmptyStorageResponse

0 commit comments

Comments
 (0)