func (c *Controller) GetBytesWritten() (int, error) {
	return c.getInfoInt("traffic/written")
}
GetBytesWritten returns total bytes uploaded.
package torgo
import (
	"encoding/hex"
	"errors"
	"fmt"
	"io/ioutil"
	"net/textproto"
	"strconv"
	"strings"
)
type Controller struct {
	AuthMethods []string
	CookieFile string
	Text *textproto.Conn
}
func NewController(addr string) (*Controller, error) {
	text, err := textproto.Dial("tcp", addr)
	if err != nil {
		return nil, err
	}
	c := &Controller{Text: text}
	err = c.getProtocolInfo()
	if err != nil {
		return nil, err
	}
	return c, nil
}
func (c *Controller) makeRequest(request string) (int, string, error) {
	id, err := c.Text.Cmd(request)
	if err != nil {
		return 0, "", err
	}
	c.Text.StartResponse(id)
	defer c.Text.EndResponse(id)
	return c.Text.ReadResponse(250)
}
func (c *Controller) getProtocolInfo() error {
	_, msg, err := c.makeRequest("PROTOCOLINFO 1")
	if err != nil {
		return err
	}
	lines := strings.Split(msg, "\n")
	authPrefix := "AUTH METHODS="
	cookiePrefix := "COOKIEFILE="
	for _, line := range lines {
		if strings.HasPrefix(line, authPrefix) {
			line = line[len(authPrefix):]
			parts := strings.SplitN(line, " ", 2)
			c.AuthMethods = strings.Split(parts[0], ",")
			if len(parts) == 2 && strings.HasPrefix(parts[1], cookiePrefix) {
				raw := parts[1][len(cookiePrefix):]
				c.CookieFile, err = strconv.Unquote(raw)
				if err != nil {
					return err
				}
			}
		}
	}
	return nil
}
func (c *Controller) getInfo(key string) (string, error) {
	_, msg, err := c.makeRequest("GETINFO " + key)
	if err != nil {
		return "", err
	}
	lines := strings.Split(msg, "\n")
	for _, line := range lines {
		parts := strings.SplitN(line, "=", 2)
		if parts[0] == key {
			return parts[1], nil
		}
	}
	return "", fmt.Errorf(key + " not found")
}
func (c *Controller) getInfoInt(key string) (int, error) {
	s, err := c.getInfo(key)
	if err != nil {
		return 0, err
	}
	return strconv.Atoi(s)
}
func (c *Controller) GetAddress() (string, error) {
	return c.getInfo("address")
}
func (c *Controller) GetBytesRead() (int, error) {
	return c.getInfoInt("traffic/read")
}