feat: upgrade core to v0.4.0, pass network to admission, add dial options
Upgrade github.com/go-gost/core from v0.3.3 to v0.4.0, adapting to interface changes: - Admit(ctx, network, addr, opts) now accepts a network parameter - Router.Dial now accepts variadic chain.DialOption, forwarded to the route's Dial call along with router-level options - gRPC/HTTP admission plugins include the new Network field Also fix two typos: ResoloverNodeOption -> ResolverNodeOption, WithHostOpton -> WithHostOption.
This commit is contained in:
@@ -104,7 +104,7 @@ func NewAdmission(opts ...Option) admission.Admission {
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *localAdmission) Admit(ctx context.Context, addr string, opts ...admission.Option) bool {
|
||||
func (p *localAdmission) Admit(ctx context.Context, network, addr string, opts ...admission.Option) bool {
|
||||
if addr == "" || p == nil {
|
||||
return true
|
||||
}
|
||||
@@ -292,9 +292,9 @@ func AdmissionGroup(admissions ...admission.Admission) admission.Admission {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *admissionGroup) Admit(ctx context.Context, addr string, opts ...admission.Option) bool {
|
||||
func (p *admissionGroup) Admit(ctx context.Context, network, addr string, opts ...admission.Option) bool {
|
||||
for _, admission := range p.admissions {
|
||||
if admission != nil && !admission.Admit(ctx, addr, opts...) {
|
||||
if admission != nil && !admission.Admit(ctx, network, addr, opts...) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ func NewGRPCPlugin(name string, addr string, opts ...plugin.Option) admission.Ad
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *grpcPlugin) Admit(ctx context.Context, addr string, opts ...admission.Option) bool {
|
||||
func (p *grpcPlugin) Admit(ctx context.Context, network, addr string, opts ...admission.Option) bool {
|
||||
if p.client == nil {
|
||||
return false
|
||||
}
|
||||
@@ -56,6 +56,7 @@ func (p *grpcPlugin) Admit(ctx context.Context, addr string, opts ...admission.O
|
||||
r, err := p.client.Admit(ctx,
|
||||
&proto.AdmissionRequest{
|
||||
Service: options.Service,
|
||||
Network: network,
|
||||
Addr: addr,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
type httpPluginRequest struct {
|
||||
Service string `json:"service"`
|
||||
Network string `json:"network"`
|
||||
Addr string `json:"addr"`
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ func NewHTTPPlugin(name string, url string, opts ...plugin.Option) admission.Adm
|
||||
}
|
||||
}
|
||||
|
||||
func (p *httpPlugin) Admit(ctx context.Context, addr string, opts ...admission.Option) (ok bool) {
|
||||
func (p *httpPlugin) Admit(ctx context.Context, network, addr string, opts ...admission.Option) (ok bool) {
|
||||
if p.client == nil {
|
||||
return
|
||||
}
|
||||
@@ -57,6 +58,7 @@ func (p *httpPlugin) Admit(ctx context.Context, addr string, opts ...admission.O
|
||||
|
||||
rb := httpPluginRequest{
|
||||
Service: options.Service,
|
||||
Network: network,
|
||||
Addr: addr,
|
||||
}
|
||||
v, err := json.Marshal(&rb)
|
||||
|
||||
@@ -35,7 +35,7 @@ func WrapConn(admission admission.Admission, c net.Conn) net.Conn {
|
||||
|
||||
func (c *serverConn) Read(b []byte) (n int, err error) {
|
||||
if c.admission != nil &&
|
||||
!c.admission.Admit(context.Background(), c.RemoteAddr().String()) {
|
||||
!c.admission.Admit(context.Background(), c.RemoteAddr().Network(), c.RemoteAddr().String()) {
|
||||
err = io.EOF
|
||||
return
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func (c *packetConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
|
||||
}
|
||||
|
||||
if c.admission != nil &&
|
||||
!c.admission.Admit(context.Background(), addr.String()) {
|
||||
!c.admission.Admit(context.Background(), addr.Network(), addr.String()) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ func (c *udpConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
|
||||
return
|
||||
}
|
||||
if c.admission != nil &&
|
||||
!c.admission.Admit(context.Background(), addr.String()) {
|
||||
!c.admission.Admit(context.Background(), addr.Network(), addr.String()) {
|
||||
continue
|
||||
}
|
||||
return
|
||||
@@ -174,7 +174,7 @@ func (c *udpConn) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error) {
|
||||
return
|
||||
}
|
||||
if c.admission != nil &&
|
||||
!c.admission.Admit(context.Background(), addr.String()) {
|
||||
!c.admission.Admit(context.Background(), addr.Network(), addr.String()) {
|
||||
continue
|
||||
}
|
||||
return
|
||||
@@ -192,7 +192,7 @@ func (c *udpConn) ReadMsgUDP(b, oob []byte) (n, oobn, flags int, addr *net.UDPAd
|
||||
return
|
||||
}
|
||||
if c.admission != nil &&
|
||||
!c.admission.Admit(context.Background(), addr.String()) {
|
||||
!c.admission.Admit(context.Background(), addr.Network(), addr.String()) {
|
||||
continue
|
||||
}
|
||||
return
|
||||
|
||||
@@ -47,7 +47,7 @@ func (ln *listener) Accept() (net.Conn, error) {
|
||||
}
|
||||
|
||||
if ln.admission != nil &&
|
||||
!ln.admission.Admit(ctx, clientAddr.String(), admission.WithService(ln.service)) {
|
||||
!ln.admission.Admit(ctx, ln.Addr().Network(), clientAddr.String(), admission.WithService(ln.service)) {
|
||||
c.Close()
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user