glider/proxy/socks5/socks5.go

51 lines
1021 B
Go
Raw Normal View History

2018-01-22 00:40:04 +08:00
// https://tools.ietf.org/html/rfc1928
2017-07-13 21:55:41 +08:00
// socks5 client:
// https://github.com/golang/net/tree/master/proxy
// 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.
// socks5 server:
// https://github.com/shadowsocks/go-shadowsocks2/tree/master/socks
package socks5
2017-07-13 21:55:41 +08:00
import (
"net/url"
2017-07-13 21:55:41 +08:00
"github.com/nadoo/glider/common/log"
2017-07-13 21:55:41 +08:00
)
2018-06-26 17:09:41 +08:00
// Version is socks5 version number
const Version = 5
2017-07-13 21:55:41 +08:00
// SOCKS5 struct
type SOCKS5 struct {
2018-03-24 19:57:46 +08:00
addr string
user string
password string
2017-07-13 21:55:41 +08:00
}
// NewSOCKS5 returns a Proxy that makes SOCKS v5 connections to the given address
2017-07-13 21:55:41 +08:00
// with an optional username and password. See RFC 1928.
func NewSOCKS5(s string) (*SOCKS5, error) {
u, err := url.Parse(s)
if err != nil {
log.F("parse err: %s", err)
return nil, err
}
addr := u.Host
2018-07-06 11:30:42 +08:00
user := u.User.Username()
pass, _ := u.User.Password()
h := &SOCKS5{
2018-03-24 19:57:46 +08:00
addr: addr,
user: user,
password: pass,
2017-07-13 21:55:41 +08:00
}
return h, nil
}