forked from gocircuit/circuit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transport.go
57 lines (48 loc) · 1.39 KB
/
transport.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2013 The Go Circuit Project
// Use of this source code is governed by the license for
// The Go Circuit Project, found in the LICENSE file.
//
// Authors:
// 2013 Petar Maymounkov <p@gocircuit.org>
// Package tele implements the circuit/use/n networking module using Teleport Transport
package tele
import (
"net"
"os"
"github.com/hoijui/circuit/pkg/kit/tele"
"github.com/hoijui/circuit/pkg/kit/tele/blend"
"github.com/hoijui/circuit/pkg/use/n"
)
func init() {
n.Bind(&System{})
}
// System is the high-level type that encloses a monolithic networking functionality
type System struct{}
// workerID is the ID for this transport endpoint.
// addr is the networking address to listen to.
func (s *System) NewTransport(workerID n.WorkerID, addr net.Addr, key []byte) n.Transport {
var u *blend.Transport
if len(key) == 0 {
u = tele.NewStructOverTCP()
} else {
u = tele.NewStructOverTCPWithHMAC(key)
}
l := newListener(workerID, os.Getpid(), u.Listen(addr))
return &Transport{
WorkerID: workerID,
Dialer: newDialer(l.Addr(), u),
Listener: l,
}
}
func (s *System) ParseNetAddr(a string) (net.Addr, error) {
return ParseNetAddr(a)
}
func (s *System) ParseAddr(a string) (n.Addr, error) {
return ParseAddr(a)
}
// Transport cumulatively represents the ability to listen for connections and dial into remote endpoints.
type Transport struct {
n.WorkerID
*Dialer
*Listener
}