syncthing/lib/model/connection.go

53 lines
1.1 KiB
Go
Raw Normal View History

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