2015-06-28 15:05:29 +00:00
|
|
|
// Copyright (C) 2015 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
// You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2015-07-17 20:22:07 +00:00
|
|
|
"crypto/tls"
|
2015-06-28 15:05:29 +00:00
|
|
|
"net"
|
|
|
|
|
|
|
|
"github.com/syncthing/protocol"
|
|
|
|
)
|
|
|
|
|
2015-07-17 20:22:07 +00:00
|
|
|
type IntermediateConnection struct {
|
2015-08-23 06:55:32 +00:00
|
|
|
*tls.Conn
|
|
|
|
Type ConnectionType
|
2015-07-17 20:22:07 +00:00
|
|
|
}
|
|
|
|
|
2015-06-28 15:05:29 +00:00
|
|
|
type Connection struct {
|
|
|
|
net.Conn
|
|
|
|
protocol.Connection
|
|
|
|
Type ConnectionType
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
2015-08-23 06:43:33 +00:00
|
|
|
ConnectionTypeDirectAccept ConnectionType = iota
|
|
|
|
ConnectionTypeDirectDial
|
2015-06-28 19:09:53 +00:00
|
|
|
ConnectionTypeRelayAccept
|
|
|
|
ConnectionTypeRelayDial
|
2015-06-28 15:05:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ConnectionType int
|
|
|
|
|
|
|
|
func (t ConnectionType) String() string {
|
|
|
|
switch t {
|
2015-08-23 06:43:33 +00:00
|
|
|
case ConnectionTypeDirectAccept:
|
|
|
|
return "direct-accept"
|
|
|
|
case ConnectionTypeDirectDial:
|
|
|
|
return "direct-dial"
|
2015-06-28 19:09:53 +00:00
|
|
|
case ConnectionTypeRelayAccept:
|
|
|
|
return "relay-accept"
|
|
|
|
case ConnectionTypeRelayDial:
|
|
|
|
return "relay-dial"
|
2015-06-28 15:05:29 +00:00
|
|
|
}
|
|
|
|
return "unknown"
|
|
|
|
}
|
2015-06-28 19:09:53 +00:00
|
|
|
|
|
|
|
func (t ConnectionType) IsDirect() bool {
|
2015-08-23 06:43:33 +00:00
|
|
|
return t == ConnectionTypeDirectAccept || t == ConnectionTypeDirectDial
|
2015-06-28 19:09:53 +00:00
|
|
|
}
|