mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-25 16:08:25 +00:00
General cleanup
This commit is contained in:
parent
e1959afb6b
commit
2505f82ce5
@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
func GetInvitationFromRelay(uri *url.URL, id syncthingprotocol.DeviceID, certs []tls.Certificate) (protocol.SessionInvitation, error) {
|
func GetInvitationFromRelay(uri *url.URL, id syncthingprotocol.DeviceID, certs []tls.Certificate) (protocol.SessionInvitation, error) {
|
||||||
if uri.Scheme != "relay" {
|
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))
|
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)
|
return protocol.SessionInvitation{}, fmt.Errorf("Incorrect response code %d: %s", msg.Code, msg.Message)
|
||||||
case protocol.SessionInvitation:
|
case protocol.SessionInvitation:
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugln("Received invitation via", conn.LocalAddr())
|
l.Debugln("Received invitation", msg, "via", conn.LocalAddr())
|
||||||
}
|
}
|
||||||
ip := net.IP(msg.Address)
|
ip := net.IP(msg.Address)
|
||||||
if len(ip) == 0 || ip.IsUnspecified() {
|
if len(ip) == 0 || ip.IsUnspecified() {
|
||||||
|
@ -5,6 +5,12 @@
|
|||||||
|
|
||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
syncthingprotocol "github.com/syncthing/protocol"
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
messageTypePing int32 = iota
|
messageTypePing int32 = iota
|
||||||
messageTypePong
|
messageTypePong
|
||||||
@ -45,3 +51,11 @@ type SessionInvitation struct {
|
|||||||
Port uint16
|
Port uint16
|
||||||
ServerSocket bool
|
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)
|
||||||
|
}
|
||||||
|
@ -51,9 +51,9 @@ func main() {
|
|||||||
go stdinReader(stdin)
|
go stdinReader(stdin)
|
||||||
|
|
||||||
if join {
|
if join {
|
||||||
log.Printf("Creating client")
|
log.Println("Creating client")
|
||||||
relay := client.NewProtocolClient(uri, []tls.Certificate{cert}, nil)
|
relay := client.NewProtocolClient(uri, []tls.Certificate{cert}, nil)
|
||||||
log.Printf("Created client")
|
log.Println("Created client")
|
||||||
|
|
||||||
go relay.Serve()
|
go relay.Serve()
|
||||||
|
|
||||||
@ -64,9 +64,9 @@ func main() {
|
|||||||
for invite := range relay.Invitations {
|
for invite := range relay.Invitations {
|
||||||
select {
|
select {
|
||||||
case recv <- invite:
|
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:
|
default:
|
||||||
log.Printf("Discarding invitation", invite)
|
log.Println("Discarding invitation", invite)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -91,7 +91,7 @@ func main() {
|
|||||||
log.Fatal(err)
|
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)
|
conn, err := client.JoinSession(invite)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("Failed to join", err)
|
log.Fatalln("Failed to join", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user