func main() { me, err := user.Current() checkErr(err) rosa.PrivateKeyPath = me.HomeDir + "/.rosa/key.priv" rosa.PublicKeyPath = me.HomeDir + "/.rosa/key.pub" rosa.FriendListPath = me.HomeDir + "/.rosa/friend_list" _PrivateKey, err = rosa.LoadPrivateKey(rosa.PrivateKeyPath) err = rosa.LoadFriends(rosa.FriendListPath) var cmdList map[string]command cmdList = make(map[string]command) cmdList["friends"] = friends cmdList["friend"] = friend cmdList["add"] = add cmdList["delete"] = deleteFriend cmdList["generate"] = generate cmdList["public"] = public cmdList["help"] = help if len(os.Args) < 2 || cmdList[os.Args[1]] == nil { checkErr(cmdList["help"]()) os.Exit(0) } checkErr(cmdList[os.Args[1]]()) }
func SendFile(IP string, port int, files []string, identity string) { rosa.LoadFriends(rosa.FriendListPath) var ip net.IP ip = net.ParseIP(IP) if ip == nil { ips, err := net.LookupIP(IP) if err != nil { Status <- errors.New("Slingshot: Not a valid IP") return } ip = ips[0] } addr := &net.TCPAddr{ IP: ip, Port: port, } conn, err := net.DialTCP("tcp", nil, addr) if err != nil { Status <- err return } for _, filename := range files { content, err := ioutil.ReadFile(filename) if err != nil { Status <- err return } p := &pellet{filename, content} tosend, err := p.toBytes() fmt.Println(tosend) if err != nil { Status <- err return } if identity != "" { f := rosa.SeekByName(identity) if f == nil { Status <- errors.New("Slingshot: Not a valid identity") return } tosend, err = f.Encrypt(tosend) fmt.Println(tosend) if err != nil { Status <- err return } } _, err = conn.Write(tosend) if err != nil { Status <- err return } } conn.Close() Status <- nil }