General cleanup

This commit is contained in:
Audrius Butkevicius 2015-07-17 20:17:49 +01:00
parent e1959afb6b
commit 2505f82ce5
3 changed files with 21 additions and 7 deletions

View File

@ -16,7 +16,7 @@ import (
func GetInvitationFromRelay(uri *url.URL, id syncthingprotocol.DeviceID, certs []tls.Certificate) (protocol.SessionInvitation, error) {
if uri.Scheme != "relay" {
return protocol.SessionInvitation{}, fmt.Errorf("Unsupported relay schema:", uri.Scheme)
return protocol.SessionInvitation{}, fmt.Errorf("Unsupported relay scheme:", uri.Scheme)
}
conn, err := tls.Dial("tcp", uri.Host, configForCerts(certs))
@ -49,7 +49,7 @@ func GetInvitationFromRelay(uri *url.URL, id syncthingprotocol.DeviceID, certs [
return protocol.SessionInvitation{}, fmt.Errorf("Incorrect response code %d: %s", msg.Code, msg.Message)
case protocol.SessionInvitation:
if debug {
l.Debugln("Received invitation via", conn.LocalAddr())
l.Debugln("Received invitation", msg, "via", conn.LocalAddr())
}
ip := net.IP(msg.Address)
if len(ip) == 0 || ip.IsUnspecified() {

View File

@ -5,6 +5,12 @@
package protocol
import (
"fmt"
syncthingprotocol "github.com/syncthing/protocol"
"net"
)
const (
messageTypePing int32 = iota
messageTypePong
@ -45,3 +51,11 @@ type SessionInvitation struct {
Port uint16
ServerSocket bool
}
func (i *SessionInvitation) String() string {
return fmt.Sprintf("%s@%s", syncthingprotocol.DeviceIDFromBytes(i.From), i.AddressString())
}
func (i *SessionInvitation) AddressString() string {
return fmt.Sprintf("%s:%d", net.IP(i.Address), i.Port)
}

View File

@ -51,9 +51,9 @@ func main() {
go stdinReader(stdin)
if join {
log.Printf("Creating client")
log.Println("Creating client")
relay := client.NewProtocolClient(uri, []tls.Certificate{cert}, nil)
log.Printf("Created client")
log.Println("Created client")
go relay.Serve()
@ -64,9 +64,9 @@ func main() {
for invite := range relay.Invitations {
select {
case recv <- invite:
log.Printf("Received invitation from %s on %s:%d", syncthingprotocol.DeviceIDFromBytes(invite.From), net.IP(invite.Address), invite.Port)
log.Println("Received invitation", invite)
default:
log.Printf("Discarding invitation", invite)
log.Println("Discarding invitation", invite)
}
}
}()
@ -91,7 +91,7 @@ func main() {
log.Fatal(err)
}
log.Printf("Received invitation from %s on %s:%d", syncthingprotocol.DeviceIDFromBytes(invite.From), net.IP(invite.Address), invite.Port)
log.Println("Received invitation", invite)
conn, err := client.JoinSession(invite)
if err != nil {
log.Fatalln("Failed to join", err)