mirror of
https://github.com/go-i2p/goSam.git
synced 2025-07-13 14:18:25 -04:00
cleaned up debug logging
This commit is contained in:
32
client.go
32
client.go
@ -3,14 +3,17 @@ package goSam
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"github.com/cryptix/go/debug"
|
||||
)
|
||||
|
||||
var ConnDebug = false
|
||||
|
||||
// A Client represents a single Connection to the SAM bridge
|
||||
type Client struct {
|
||||
SamConn net.Conn
|
||||
verbose bool
|
||||
rd *bufio.Reader
|
||||
}
|
||||
|
||||
// NewDefaultClient creates a new client, connecting to the default host:port at localhost:7656
|
||||
@ -24,19 +27,16 @@ func NewClient(addr string) (*Client, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ConnDebug {
|
||||
conn = debug.WrapConn(conn)
|
||||
}
|
||||
c := &Client{
|
||||
SamConn: conn,
|
||||
verbose: false,
|
||||
rd: bufio.NewReader(conn),
|
||||
}
|
||||
return c, c.hello()
|
||||
}
|
||||
|
||||
// ToggleVerbose switches logging on or off.
|
||||
// (also passed to new clients inside Dial.)
|
||||
func (c *Client) ToggleVerbose() {
|
||||
c.verbose = !c.verbose
|
||||
}
|
||||
|
||||
// send the initial handshake command and check that the reply is ok
|
||||
func (c *Client) hello() (err error) {
|
||||
var r *Reply
|
||||
@ -63,22 +63,12 @@ func (c *Client) sendCmd(cmd string) (r *Reply, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.verbose {
|
||||
log.Printf(">Send>'%s'\n", cmd)
|
||||
}
|
||||
|
||||
reader := bufio.NewReader(c.SamConn)
|
||||
line, err := reader.ReadString('\n')
|
||||
line, err := c.rd.ReadString('\n')
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if c.verbose {
|
||||
log.Printf("<Rcvd<'%s'\n", line)
|
||||
}
|
||||
|
||||
r, err = parseReply(line)
|
||||
return
|
||||
return parseReply(line)
|
||||
}
|
||||
|
||||
// Close the underlying socket to SAM
|
||||
|
Reference in New Issue
Block a user