mirror of
				https://github.com/ehang-io/nps
				synced 2025-10-30 15:26:58 +08:00 
			
		
		
		
	 9bb847df87
			
		
	
	9bb847df87
	
	
	
		
			
			* client net dail timeout
* Delete conn.go
mux 已变更设计
* Revert "Delete conn.go"
This reverts commit 0c944ec41d.
* Update client.go
		
	
		
			
				
	
	
		
			64 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package conn
 | |
| 
 | |
| import "time"
 | |
| 
 | |
| type Secret struct {
 | |
| 	Password string
 | |
| 	Conn     *Conn
 | |
| }
 | |
| 
 | |
| func NewSecret(p string, conn *Conn) *Secret {
 | |
| 	return &Secret{
 | |
| 		Password: p,
 | |
| 		Conn:     conn,
 | |
| 	}
 | |
| }
 | |
| 
 | |
| type Link struct {
 | |
| 	ConnType   string //连接类型
 | |
| 	Host       string //目标
 | |
| 	Crypt      bool   //加密
 | |
| 	Compress   bool
 | |
| 	LocalProxy bool
 | |
| 	RemoteAddr string
 | |
| 	Option     Options
 | |
| }
 | |
| 
 | |
| type Option func(*Options)
 | |
| 
 | |
| type Options struct {
 | |
| 	Timeout time.Duration
 | |
| }
 | |
| 
 | |
| var defaultTimeOut = time.Second * 5
 | |
| 
 | |
| func NewLink(connType string, host string, crypt bool, compress bool, remoteAddr string, localProxy bool, opts ...Option) *Link {
 | |
| 	options := newOptions(opts...)
 | |
| 
 | |
| 	return &Link{
 | |
| 		RemoteAddr: remoteAddr,
 | |
| 		ConnType:   connType,
 | |
| 		Host:       host,
 | |
| 		Crypt:      crypt,
 | |
| 		Compress:   compress,
 | |
| 		LocalProxy: localProxy,
 | |
| 		Option:     options,
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func newOptions(opts ...Option) Options {
 | |
| 	opt := Options{
 | |
| 		Timeout: defaultTimeOut,
 | |
| 	}
 | |
| 	for _, o := range opts {
 | |
| 		o(&opt)
 | |
| 	}
 | |
| 	return opt
 | |
| }
 | |
| 
 | |
| func LinkTimeout(t time.Duration) Option {
 | |
| 	return func(opt *Options) {
 | |
| 		opt.Timeout = t
 | |
| 	}
 | |
| }
 |