This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
config.go
101 lines (85 loc) · 2.89 KB
/
config.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
(c) Copyright NetFoundry, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package xlink_transport
import (
"fmt"
"github.com/openziti/foundation/channel2"
"github.com/openziti/foundation/transport"
"github.com/pkg/errors"
"reflect"
)
func loadListenerConfig(data map[interface{}]interface{}) (*listenerConfig, error) {
config := &listenerConfig{}
if value, found := data["bind"]; found {
if addressString, ok := value.(string); ok {
if address, err := transport.ParseAddress(addressString); err == nil {
config.bind = address
config.advertise = address
} else {
return nil, fmt.Errorf("error parsing 'bind' address in listener config (%w)", err)
}
} else {
return nil, fmt.Errorf("invalid 'bind' address in listener config (%s)", reflect.TypeOf(value))
}
} else {
return nil, fmt.Errorf("missing 'bind' address in listener config")
}
if value, found := data["advertise"]; found {
if addressString, ok := value.(string); ok {
if address, err := transport.ParseAddress(addressString); err == nil {
config.advertise = address
} else {
return nil, fmt.Errorf("error parsing 'advertise' address in listener config")
}
} else {
return nil, fmt.Errorf("invalid 'advertise' address in listener config (%s)", reflect.TypeOf(value))
}
}
if value, found := data["options"]; found {
if submap, ok := value.(map[interface{}]interface{}); ok {
config.options = channel2.LoadOptions(submap)
} else {
return nil, fmt.Errorf("invalid 'options' in listener config (%s)", reflect.TypeOf(value))
}
} else {
config.options = channel2.DefaultOptions()
}
return config, nil
}
type listenerConfig struct {
bind transport.Address
advertise transport.Address
options *channel2.Options
}
func loadDialerConfig(data map[interface{}]interface{}) (*dialerConfig, error) {
config := &dialerConfig{split: true}
if value, found := data["split"]; found {
if split, ok := value.(bool); ok {
config.split = split
} else {
return nil, errors.Errorf("invalid 'split' flag in listener config (%s)", reflect.TypeOf(value))
}
}
if value, found := data["options"]; found {
if submap, ok := value.(map[interface{}]interface{}); ok {
config.options = channel2.LoadOptions(submap)
} else {
return nil, fmt.Errorf("invalid 'options' in dialer config (%s)", reflect.TypeOf(value))
}
}
return config, nil
}
type dialerConfig struct {
split bool
options *channel2.Options
}