Example #1
0
func deleteFriend() error {
	if len(os.Args) < 3 {
		return errors.New("Not enought parameter to delete a friend\n Rosae delete usage => rosae delete friend_name")
	}
	him := rosa.SeekByName(os.Args[2])
	if him == nil {
		return errors.New("Friend not found\n")
	}
	return him.Delete(rosa.FriendListPath)
}
Example #2
0
func friend() error {
	if len(os.Args) < 3 {
		return errors.New("Not enought parameter to find a friend\n Rosae friend usage => rosae friend friend_name")
	}
	him := rosa.SeekByName(os.Args[2])
	if him == nil {
		return errors.New("Friend not found")
	}
	fmt.Println(rosa.StringifyPublicKey(him.PublicKey))
	return nil
}
Example #3
0
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
}