| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package v4
- import (
- "github.com/golang/protobuf/proto"
- "github.com/v2fly/v2ray-core/v5/common/protocol"
- "github.com/v2fly/v2ray-core/v5/common/serial"
- "github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
- "github.com/v2fly/v2ray-core/v5/proxy/hysteria2"
- )
- // Hysteria2ServerTarget is configuration of a single hysteria2 server
- type Hysteria2ServerTarget struct {
- Address *cfgcommon.Address `json:"address"`
- Port uint16 `json:"port"`
- Email string `json:"email"`
- Level byte `json:"level"`
- }
- // Hysteria2ClientConfig is configuration of hysteria2 servers
- type Hysteria2ClientConfig struct {
- Servers []*Hysteria2ServerTarget `json:"servers"`
- }
- // Build implements Buildable
- func (c *Hysteria2ClientConfig) Build() (proto.Message, error) {
- config := new(hysteria2.ClientConfig)
- if len(c.Servers) == 0 {
- return nil, newError("0 Hysteria2 server configured.")
- }
- serverSpecs := make([]*protocol.ServerEndpoint, len(c.Servers))
- for idx, rec := range c.Servers {
- if rec.Address == nil {
- return nil, newError("Hysteria2 server address is not set.")
- }
- if rec.Port == 0 {
- return nil, newError("Invalid Hysteria2 port.")
- }
- account := &hysteria2.Account{}
- hysteria2 := &protocol.ServerEndpoint{
- Address: rec.Address.Build(),
- Port: uint32(rec.Port),
- User: []*protocol.User{
- {
- Level: uint32(rec.Level),
- Email: rec.Email,
- Account: serial.ToTypedMessage(account),
- },
- },
- }
- serverSpecs[idx] = hysteria2
- }
- config.Server = serverSpecs
- return config, nil
- }
- // Hysteria2ServerConfig is Inbound configuration
- type Hysteria2ServerConfig struct{}
- // Build implements Buildable
- func (c *Hysteria2ServerConfig) Build() (proto.Message, error) {
- config := new(hysteria2.ServerConfig)
- return config, nil
- }
|