syncthing/lib/model/connection.go

53 lines
1.1 KiB
Go
Raw Normal View History

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 (
"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
)
type IntermediateConnection struct {
*tls.Conn
Type ConnectionType
}
2015-06-28 08:05:29 -07:00
type Connection struct {
net.Conn
protocol.Connection
Type ConnectionType
}
const (
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 {
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 {
return t == ConnectionTypeDirectAccept || t == ConnectionTypeDirectDial
2015-06-28 12:09:53 -07:00
}