Example #1
0
// GetSpecificAuth fetches a message from a specific server using authentication
func (proto *Proto) GetSpecificAuth(server, auth string, messageID []byte) ([]byte, error) {
	messageIDenc := utils.B58encode(messageID)
	body, err := socks.Proxy(proto.SocksServer).LimitGet(constructURL(server, "/fetch", "?messageid=", messageIDenc, "&auth=", auth), 512000)
	if err != nil {
		return nil, err
	}
	return parseError(body)
}
Example #2
0
// GetGlobalIndex returns the global index of a server
func (proto *Proto) GetGlobalIndex(server, auth string, start, count int) (messages []*structs.MessageStruct, more bool, err error) {
	url := constructURL(server, "/globalindex?auth=", auth, "&start=", strconv.Itoa(start), "count=", strconv.Itoa(count))
	body, err := socks.Proxy(proto.SocksServer).LimitGet(url, 5242880)
	if err != nil {
		return nil, false, err
	}
	return parseListResponse(body)
}
Example #3
0
// Notify a server
func (proto *Proto) Notify(server, auth string) error {
	body, err := socks.Proxy(proto.SocksServer).LimitGet(constructURL(server, "/notify?auth=", auth), 4096)
	if err != nil {
		return err
	}
	_, err = parseError(body)
	return err
}
Example #4
0
// PostSpecific posts a message to a specific server
func (proto *Proto) PostSpecific(server string, message []byte) error {
	body, err := socks.Proxy(proto.SocksServer).LimitPostBytes(constructURL(server, "/post"), "text/text", message, 512000)
	if err != nil {
		return err
	}
	_, err = parseError(body) // we do not care about the body
	return err
}
Example #5
0
// ID returns the ID of a specific server
func (proto *Proto) ID(server string) (*ServerInfo, error) {
	body, err := socks.Proxy(proto.SocksServer).LimitGet(constructURL(server, "/id"), 4096)
	if err != nil {
		return nil, err
	}
	si := new(ServerInfo)
	err = json.Unmarshal(body, si)
	if err != nil {
		return nil, err
	}
	return si, nil
}
Example #6
0
// ListSpecific lists the messages for pubKey from a specific server
func (proto *Proto) ListSpecific(server string, pubKey, privKey []byte, start, count int) (messages []*structs.MessageStruct, more bool, err error) {
	var authStr string
	var myPubKey message.Curve25519Key
	copy(myPubKey[:], pubKey)
	if message.KeyIsHidden(&myPubKey) {
		if privKey == nil {
			return nil, false, ErrPrivKey
		}
		auth, err := proto.Auth(server, privKey)
		if err != nil {
			return nil, false, err
		}
		authStr = "&auth=" + auth
	}
	url := constructURL(server, "/keyindex?key=", utils.B58encode(pubKey[:]), "&start=", strconv.Itoa(start), "count=", strconv.Itoa(count), authStr)
	body, err := socks.Proxy(proto.SocksServer).LimitGet(url, 512000)
	if err != nil {
		return nil, false, err
	}
	return parseListResponse(body)
}