-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
- Loading branch information
Showing
23 changed files
with
702 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package proxy | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"net/netip" | ||
|
||
"github.com/Asutorufa/yuhaiin/pkg/net/interfaces/dns" | ||
"github.com/Asutorufa/yuhaiin/pkg/protos/statistic" | ||
) | ||
|
||
type Proxy interface { | ||
StreamProxy | ||
PacketProxy | ||
Dispatch(context.Context, Address) (Address, error) | ||
} | ||
|
||
type StreamProxy interface { | ||
Conn(context.Context, Address) (net.Conn, error) | ||
} | ||
|
||
type PacketProxy interface { | ||
PacketConn(context.Context, Address) (net.PacketConn, error) | ||
} | ||
|
||
type Port interface { | ||
Port() uint16 | ||
String() string | ||
} | ||
|
||
type Type uint8 | ||
|
||
func (t Type) String() string { | ||
switch t { | ||
case DOMAIN: | ||
return "DOMAIN" | ||
case IP: | ||
return "IP" | ||
case UNIX: | ||
return "UNIX" | ||
case EMPTY: | ||
return "EMPTY" | ||
default: | ||
return "UNKNOWN" | ||
} | ||
} | ||
|
||
const ( | ||
DOMAIN Type = 1 | ||
IP Type = 2 | ||
UNIX Type = 3 | ||
EMPTY Type = 4 | ||
) | ||
|
||
type Address interface { | ||
// Hostname return hostname of address, eg: www.example.com, 127.0.0.1, ff::ff | ||
Hostname() string | ||
// IP return net.IP, if address is ip else resolve the domain and return one of ips | ||
IP(context.Context) (net.IP, error) | ||
AddrPort(context.Context) (netip.AddrPort, error) | ||
// Port return port of address | ||
Port() Port | ||
// Type return type of address, domain or ip | ||
Type() Type | ||
NetworkType() statistic.Type | ||
|
||
net.Addr | ||
|
||
// WithResolver will use call IP(), IPHost(), UDPAddr(), TCPAddr() | ||
// return the current resolver is applied, if can't cover return false | ||
WithResolver(_ dns.DNS, canCover bool) bool | ||
// OverrideHostname clone address(exclude Values) and change hostname | ||
OverrideHostname(string) Address | ||
OverridePort(Port) Address | ||
|
||
UDPAddr(context.Context) (*net.UDPAddr, error) | ||
TCPAddr(context.Context) (*net.TCPAddr, error) | ||
|
||
WithValue(key, value any) | ||
Value(key any) (any, bool) | ||
RangeValue(func(k, v any) bool) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2014 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
) | ||
|
||
// Copyright 2015 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// package goos contains GOOS-specific constants. | ||
|
||
// The next line makes 'go generate' write the zgoos*.go files with | ||
// per-OS information, including constants named Is$GOOS for every | ||
// known GOOS. The constant is 1 on the current system, 0 otherwise; | ||
// multiplying by them is useful for defining GOOS-specific constants. | ||
// | ||
//go:generate go run gengoos.go | ||
|
||
var gooses []string | ||
|
||
func main() { | ||
data, err := os.ReadFile("syslist.go") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
const goosPrefix = `var knownOS = map[string]bool{` | ||
inGOOS := false | ||
for _, line := range strings.Split(string(data), "\n") { | ||
if strings.HasPrefix(line, goosPrefix) { | ||
inGOOS = true | ||
} else if inGOOS && strings.HasPrefix(line, "}") { | ||
break | ||
} else if inGOOS { | ||
goos := strings.Fields(line)[0] | ||
goos = strings.TrimPrefix(goos, `"`) | ||
goos = strings.TrimSuffix(goos, `":`) | ||
gooses = append(gooses, goos) | ||
} | ||
} | ||
|
||
for _, target := range gooses { | ||
if target == "nacl" { | ||
continue | ||
} | ||
var tags []string | ||
if target == "linux" { | ||
tags = append(tags, "!android") // must explicitly exclude android for linux | ||
} | ||
if target == "solaris" { | ||
tags = append(tags, "!illumos") // must explicitly exclude illumos for solaris | ||
} | ||
if target == "darwin" { | ||
tags = append(tags, "!ios") // must explicitly exclude ios for darwin | ||
} | ||
tags = append(tags, target) // must explicitly include target for bootstrapping purposes | ||
var buf bytes.Buffer | ||
fmt.Fprintf(&buf, "// Code generated by gengoos.go using 'go generate'. DO NOT EDIT.\n\n") | ||
fmt.Fprintf(&buf, "//go:build %s\n\n", strings.Join(tags, " && ")) | ||
fmt.Fprintf(&buf, "package goos\n\n") | ||
fmt.Fprintf(&buf, "const GOOS = `%s`\n\n", target) | ||
for _, goos := range gooses { | ||
value := 0 | ||
if goos == target { | ||
value = 1 | ||
} | ||
fmt.Fprintf(&buf, "const Is%s = %d\n", strings.Title(goos), value) | ||
} | ||
err := os.WriteFile("zgoos_"+target+".go", buf.Bytes(), 0666) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2011 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package goos | ||
|
||
// Note that this file is read by internal/goarch/gengoarch.go and by | ||
// internal/goos/gengoos.go. If you change this file, look at those | ||
// files as well. | ||
|
||
// knownOS is the list of past, present, and future known GOOS values. | ||
// Do not remove from this list, as it is used for filename matching. | ||
// If you add an entry to this list, look at unixOS, below. | ||
var knownOS = map[string]bool{ | ||
"aix": true, | ||
"android": true, | ||
"darwin": true, | ||
"dragonfly": true, | ||
"freebsd": true, | ||
"hurd": true, | ||
"illumos": true, | ||
"ios": true, | ||
"js": true, | ||
"linux": true, | ||
"nacl": true, | ||
"netbsd": true, | ||
"openbsd": true, | ||
"plan9": true, | ||
"solaris": true, | ||
"wasip1": true, | ||
"windows": true, | ||
"zos": true, | ||
} | ||
|
||
// unixOS is the set of GOOS values matched by the "unix" build tag. | ||
// This is not used for filename matching. | ||
// This list also appears in cmd/dist/build.go and | ||
// cmd/go/internal/imports/build.go. | ||
var unixOS = map[string]bool{ | ||
"aix": true, | ||
"android": true, | ||
"darwin": true, | ||
"dragonfly": true, | ||
"freebsd": true, | ||
"hurd": true, | ||
"illumos": true, | ||
"ios": true, | ||
"linux": true, | ||
"netbsd": true, | ||
"openbsd": true, | ||
"solaris": true, | ||
} | ||
|
||
// knownArch is the list of past, present, and future known GOARCH values. | ||
// Do not remove from this list, as it is used for filename matching. | ||
var knownArch = map[string]bool{ | ||
"386": true, | ||
"amd64": true, | ||
"amd64p32": true, | ||
"arm": true, | ||
"armbe": true, | ||
"arm64": true, | ||
"arm64be": true, | ||
"loong64": true, | ||
"mips": true, | ||
"mipsle": true, | ||
"mips64": true, | ||
"mips64le": true, | ||
"mips64p32": true, | ||
"mips64p32le": true, | ||
"ppc": true, | ||
"ppc64": true, | ||
"ppc64le": true, | ||
"riscv": true, | ||
"riscv64": true, | ||
"s390": true, | ||
"s390x": true, | ||
"sparc": true, | ||
"sparc64": true, | ||
"wasm": true, | ||
} |
Oops, something went wrong.