2024-03-31 09:31:50 +11:00
|
|
|
/*
|
|
|
|
Copyright 2024 Josh Deprez
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
http://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.
|
|
|
|
*/
|
|
|
|
|
2024-03-24 18:01:24 +11:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2024-04-06 17:46:00 +11:00
|
|
|
"github.com/sfiera/multitalk/pkg/ddp"
|
2024-03-24 18:01:24 +11:00
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
type config struct {
|
|
|
|
// Optional: default is 387.
|
|
|
|
ListenPort uint16 `yaml:"listen_port"`
|
|
|
|
|
|
|
|
// Sets the Domain Identifier used by this router.
|
|
|
|
// Note: this does not "bind" the IP side of the router to a particular
|
|
|
|
// interface; it will listen on all interfaces with IP addresses.
|
|
|
|
// Optional: defaults to the first global unicast address on any local
|
|
|
|
// network interface.
|
|
|
|
LocalIP string `yaml:"local_ip"`
|
|
|
|
|
|
|
|
// Required for routing a local EtherTalk network.
|
|
|
|
EtherTalk struct {
|
2024-04-17 12:14:33 +10:00
|
|
|
EthAddr string `yaml:"ethernet_addr"`
|
2024-04-06 17:46:00 +11:00
|
|
|
Device string `yaml:"device"`
|
|
|
|
ZoneName string `yaml:"zone_name"`
|
|
|
|
NetStart ddp.Network `yaml:"net_start"`
|
|
|
|
NetEnd ddp.Network `yaml:"net_end"`
|
2024-03-24 18:01:24 +11:00
|
|
|
} `yaml:"ethertalk"`
|
|
|
|
|
|
|
|
// LocalTalk struct {
|
|
|
|
// ZoneName string `yaml:"zone_name"`
|
|
|
|
// Network uint16 `yaml:"network"`
|
|
|
|
// } `yaml:"localtalk"`
|
|
|
|
|
|
|
|
// Allow routers other than those listed under peers?
|
|
|
|
OpenPeering bool `yaml:"open_peering"`
|
|
|
|
|
|
|
|
// List of peer routers.
|
|
|
|
Peers []string `yaml:"peers"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadConfig(cfgPath string) (*config, error) {
|
|
|
|
f, err := os.Open(cfgPath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
c := new(config)
|
|
|
|
if err := yaml.NewDecoder(f).Decode(c); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.ListenPort == 0 {
|
|
|
|
c.ListenPort = 387
|
|
|
|
}
|
|
|
|
|
|
|
|
return c, nil
|
|
|
|
}
|