V2bX/core/hy/node.go

43 lines
944 B
Go
Raw Normal View History

package hy
import (
"errors"
"fmt"
"github.com/Yuzuki616/V2bX/api/panel"
"github.com/Yuzuki616/V2bX/conf"
2023-06-15 22:04:39 -04:00
"github.com/Yuzuki616/V2bX/limiter"
)
func (h *Hy) AddNode(tag string, info *panel.NodeInfo, c *conf.ControllerConfig) error {
if info.Type != "hysteria" {
return errors.New("the core not support " + info.Type)
}
2023-06-09 00:36:49 -04:00
switch c.CertConfig.CertMode {
case "reality", "none", "":
return errors.New("hysteria need normal tls cert")
}
2023-06-15 22:04:39 -04:00
l, err := limiter.GetLimiter(tag)
if err != nil {
return fmt.Errorf("get limiter error: %s", err)
}
s := NewServer(tag, l)
err = s.runServer(info, c)
if err != nil {
return fmt.Errorf("run hy server error: %s", err)
}
h.servers.Store(tag, s)
return nil
}
func (h *Hy) DelNode(tag string) error {
if s, e := h.servers.Load(tag); e {
2023-06-18 20:34:59 -04:00
err := s.(*Server).Close()
if err != nil {
return err
}
h.servers.Delete(tag)
return nil
}
return errors.New("the node is not have")
}