-
Notifications
You must be signed in to change notification settings - Fork 28
/
host.go
42 lines (34 loc) · 889 Bytes
/
host.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
package routertwo
import (
"context"
"errors"
"net"
"time"
)
// ErrOffline used to indicate an offline host
var ErrOffline = errors.New("peer offline")
// Host represents a host that can be offline
type Host struct {
Routable `json:"-"`
Name string `json:"name"`
// LastSeen is used when garbage collecting
LastSeen time.Time `json:"lastseen"`
Created time.Time `json:"created"`
}
// FQDN returns the fully qualified domain name for this host
func (h *Host) FQDN() string {
return h.Name
}
// DialContext dials this host
func (h *Host) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
if h.Routable == nil {
return nil, ErrOffline
}
return h.Routable.DialContext(ctx, network, address)
}
// Replaced indicates to this host, that it have been replaced
func (h *Host) Replaced() {
if h.Routable != nil {
h.Routable.Replaced()
}
}