2015-06-28 08:05:29 -07: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 13:22:07 -07:00
|
|
|
"crypto/tls"
|
2015-06-28 08:05:29 -07:00
|
|
|
"net"
|
|
|
|
|
2015-09-22 10:38:46 -07:00
|
|
|
"github.com/syncthing/syncthing/lib/protocol"
|
2015-06-28 08:05:29 -07:00
|
|
|
)
|
|
|
|
|
2015-07-17 13:22:07 -07:00
|
|
|
type IntermediateConnection struct {
|
2015-08-22 23:55:32 -07:00
|
|
|
*tls.Conn
|
|
|
|
Type ConnectionType
|
2015-07-17 13:22:07 -07:00
|
|
|
}
|
|
|
|
|
2015-06-28 08:05:29 -07:00
|
|
|
type Connection struct {
|
|
|
|
net.Conn
|
|
|
|
protocol.Connection
|
|
|
|
Type ConnectionType
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
2015-08-22 23:43:33 -07:00
|
|
|
ConnectionTypeDirectAccept ConnectionType = iota
|
|
|
|
ConnectionTypeDirectDial
|
2015-06-28 12:09:53 -07:00
|
|
|
ConnectionTypeRelayAccept
|
|
|
|
ConnectionTypeRelayDial
|
2015-06-28 08:05:29 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
type ConnectionType int
|
|
|
|
|
|
|
|
func (t ConnectionType) String() string {
|
|
|
|
switch t {
|
2015-08-22 23:43:33 -07:00
|
|
|
case ConnectionTypeDirectAccept:
|
|
|
|
return "direct-accept"
|
|
|
|
case ConnectionTypeDirectDial:
|
|
|
|
return "direct-dial"
|
2015-06-28 12:09:53 -07:00
|
|
|
case ConnectionTypeRelayAccept:
|
|
|
|
return "relay-accept"
|
|
|
|
case ConnectionTypeRelayDial:
|
|
|
|
return "relay-dial"
|
2015-06-28 08:05:29 -07:00
|
|
|
}
|
|
|
|
return "unknown"
|
|
|
|
}
|
2015-06-28 12:09:53 -07:00
|
|
|
|
|
|
|
func (t ConnectionType) IsDirect() bool {
|
2015-08-22 23:43:33 -07:00
|
|
|
return t == ConnectionTypeDirectAccept || t == ConnectionTypeDirectDial
|
2015-06-28 12:09:53 -07:00
|
|
|
}
|