Merge pull request #102 from sheerun/server-params
Move values handling to server.go
This commit is contained in:
commit
561b4b100d
1
cmd/gost/.gitignore
vendored
Normal file
1
cmd/gost/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
gost
|
@ -1,17 +1,17 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ginuerzh/gost"
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"golang.org/x/net/http2"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/ginuerzh/gost"
|
||||||
|
"github.com/golang/glog"
|
||||||
|
"golang.org/x/net/http2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -68,18 +68,7 @@ func main() {
|
|||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(node gost.ProxyNode) {
|
go func(node gost.ProxyNode) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
certFile, keyFile := node.Get("cert"), node.Get("key")
|
server := gost.NewProxyServer(node, chain)
|
||||||
if certFile == "" {
|
|
||||||
certFile = gost.DefaultCertFile
|
|
||||||
}
|
|
||||||
if keyFile == "" {
|
|
||||||
keyFile = gost.DefaultKeyFile
|
|
||||||
}
|
|
||||||
cert, err := gost.LoadCertificate(certFile, keyFile)
|
|
||||||
if err != nil {
|
|
||||||
glog.Fatal(err)
|
|
||||||
}
|
|
||||||
server := gost.NewProxyServer(node, chain, &tls.Config{Certificates: []tls.Certificate{cert}})
|
|
||||||
glog.Fatal(server.Serve())
|
glog.Fatal(server.Serve())
|
||||||
}(serverNode)
|
}(serverNode)
|
||||||
}
|
}
|
||||||
|
3
gost.go
3
gost.go
@ -4,11 +4,12 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/golang/glog"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
28
server.go
28
server.go
@ -3,17 +3,18 @@ package gost
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"github.com/ginuerzh/gosocks4"
|
|
||||||
"github.com/ginuerzh/gosocks5"
|
|
||||||
"github.com/golang/glog"
|
|
||||||
ss "github.com/shadowsocks/shadowsocks-go/shadowsocks"
|
|
||||||
"golang.org/x/crypto/ssh"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/ginuerzh/gosocks4"
|
||||||
|
"github.com/ginuerzh/gosocks5"
|
||||||
|
"github.com/golang/glog"
|
||||||
|
ss "github.com/shadowsocks/shadowsocks-go/shadowsocks"
|
||||||
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProxyServer struct {
|
type ProxyServer struct {
|
||||||
@ -25,13 +26,22 @@ type ProxyServer struct {
|
|||||||
ota bool
|
ota bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProxyServer(node ProxyNode, chain *ProxyChain, config *tls.Config) *ProxyServer {
|
func NewProxyServer(node ProxyNode, chain *ProxyChain) *ProxyServer {
|
||||||
|
certFile, keyFile := node.certFile(), node.keyFile()
|
||||||
|
|
||||||
|
cert, err := LoadCertificate(certFile, keyFile)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
config := &tls.Config{
|
||||||
|
Certificates: []tls.Certificate{cert},
|
||||||
|
}
|
||||||
|
|
||||||
if chain == nil {
|
if chain == nil {
|
||||||
chain = NewProxyChain()
|
chain = NewProxyChain()
|
||||||
}
|
}
|
||||||
if config == nil {
|
|
||||||
config = &tls.Config{}
|
|
||||||
}
|
|
||||||
|
|
||||||
var cipher *ss.Cipher
|
var cipher *ss.Cipher
|
||||||
var ota bool
|
var ota bool
|
||||||
|
Loading…
Reference in New Issue
Block a user