コード例 #1
0
ファイル: huk.go プロジェクト: imagest/huk
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(
			"The key for your file (%v) is %v.\n"+
				"Tell your friend to run '$ huk get %v'\n"+
				"Waiting for connection...\n",
			filePath,
			myKey,
			myKey,
		)
		server.Run(strconv.Itoa(myAddr.Port), filePath)
		// create server on port_x
		// listen for connections
		// 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]
		//userName := args[2]
		fmt.Printf(
			"Searching for '%v' on your local network..\n",
			myKey,
		)
		// Client Case
		targetAddr := key.ToAddr(myKey)
		// make sure key doesnt have anything but alphabet
		//client.ReceiveInOneChunk(targetAddr.IP, strconv.Itoa(targetAddr.Port), userName)
		client.ReceiveInOneChunk(targetAddr.IP, strconv.Itoa(targetAddr.Port), "")
		// Find server IP by going through list (192.168.0.[1..255]:port_x)
		// connection established
		// generate pgp (private and public keys)
		// send public key to server
		// save encrypted file from stream
		// decrypt using private key
	default:
		// Invalid Args
		log.Fatal("I need either a filePath or a key ex: '$ huk get filePath.txt' or '$ huk key'")
	}
}
コード例 #2
0
ファイル: huk.go プロジェクト: gophergala2016/huk
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'")
	}
}