-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhuk.go
88 lines (78 loc) · 1.98 KB
/
huk.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"fmt"
"github.com/gophergala2016/huk/client"
"github.com/gophergala2016/huk/config"
"github.com/gophergala2016/huk/key"
"github.com/gophergala2016/huk/server"
"log"
"os"
)
func main() {
var filePath string
var myKey string
var myAddr key.Addr
args := os.Args[1:]
action := args[0]
switch action {
case "init":
// run the initialization
config.Init()
case "send":
// server
filePath = args[1]
myAddr = key.MyAddress()
myKey = key.AddrToKey(myAddr)
fmt.Printf("Address %v:%v \n", myAddr.IP, myAddr.Port)
fmt.Printf("Conversion to Key: %v \n", myKey)
fmt.Println("Converted Back to Address", key.ToAddr(myKey))
fmt.Printf(
"The key for your file (%v) is %v.\n"+
"Tell your friend to run '$ huk %v'\n"+
"Waiting for connection...\n",
filePath,
myKey,
myKey,
)
//server.Run(strconv.Itoa(addr.Port), filePath)
// create server on port given listen for connections
conn := server.Listen(myAddr.Port)
for {
server.CreateInitialBuffer(conn, filePath)
// conn.Write(file)
}
// validate incoming request with given key
// connection established
// recieves clients public key
// encrypt file using client's pub key
// send encrypted file over stream to client
case "get":
myKey = args[1]
fmt.Printf(
"Searching for '%v' on your local network..\n",
myKey,
)
// decifer server address from key
serverAddr := key.ToAddr(myKey)
// dial server and connect
conn := client.DialServer(serverAddr.IP, serverAddr.Port)
// get username from config
username := config.GetVariable("username")
username += "\n"
// send username
conn.Write([]byte(username))
directory := config.GetVariable("directory")
client.Receive(conn, directory+"/filename.txt")
default:
// Invalid Args
log.Fatal("I need either a filePath or a key ex: '$ huk -f filePath.txt' or '$ huk key'")
}
}
func isAlpha(input string) bool {
for _, c := range input {
if 'a' > c || c > 'z' {
return false
}
}
return true
}