kayos
471f7690d2
* Fix: Didn't unlock ._. * Refactor: reduce complexity * Fix: part of my commit message ended up in the commit :^) * Fix: mutex locking snafu * Fix: if proxy disqualified then it's not still good * Fix race cond. in socks lib + add tests + update uagents * Chore: tidy up * Fix: bad var name * Testing: Make integration test more realistic * Update CI * Fix go vet: returning fatal from goroutine * Fix: remove gotrace * CI: Add PR summarizer * Chore: gomod * Chore[CI]: fix branch in workflow
62 lines
1.0 KiB
Go
62 lines
1.0 KiB
Go
package prox5
|
|
|
|
import (
|
|
"sync"
|
|
"sync/atomic"
|
|
|
|
"git.tcp.direct/kayos/common/pool"
|
|
)
|
|
|
|
type ProxyProtocol int8
|
|
|
|
const (
|
|
// ProtoNull is a null value for ProxyProtocol.
|
|
ProtoNull ProxyProtocol = iota
|
|
ProtoSOCKS4
|
|
ProtoSOCKS4a
|
|
ProtoSOCKS5
|
|
ProtoHTTP
|
|
)
|
|
|
|
var protoMap = map[ProxyProtocol]string{
|
|
ProtoSOCKS5: "socks5", ProtoNull: "unknown", ProtoSOCKS4: "socks4", ProtoSOCKS4a: "socks4a",
|
|
}
|
|
|
|
func (p ProxyProtocol) String() string {
|
|
return protoMap[p]
|
|
}
|
|
|
|
type proto struct {
|
|
proto *atomic.Value
|
|
// immutable
|
|
*sync.Once
|
|
}
|
|
|
|
func newImmutableProto() proto {
|
|
p := proto{
|
|
proto: &atomic.Value{},
|
|
Once: &sync.Once{},
|
|
}
|
|
p.proto.Store(ProtoNull)
|
|
return p
|
|
}
|
|
|
|
func (p *proto) Get() ProxyProtocol {
|
|
return p.proto.Load().(ProxyProtocol)
|
|
}
|
|
|
|
func (p *proto) set(proxyproto ProxyProtocol) {
|
|
p.Do(func() {
|
|
p.proto.Store(proxyproto)
|
|
})
|
|
}
|
|
|
|
func (p ProxyProtocol) writeProtoString(builder *pool.String) {
|
|
builder.MustWriteString(p.String())
|
|
}
|
|
|
|
func (p ProxyProtocol) writeProtoURI(builder *pool.String) {
|
|
p.writeProtoString(builder)
|
|
builder.MustWriteString("://")
|
|
}
|