Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "log"
  7. "os"
  8. "os/signal"
  9. "syscall"
  10. "time"
  11.  
  12. "github.com/riobard/go-shadowsocks2/core"
  13. )
  14.  
  15. var config struct {
  16. Verbose bool
  17. UDPTimeout time.Duration
  18. }
  19.  
  20. func logf(f string, v ...interface{}) {
  21. if config.Verbose {
  22. log.Printf(f, v...)
  23. }
  24. }
  25.  
  26. var settings struct {
  27. Server string `json:"server"`
  28. ServerPort int `json:"server_port"`
  29. LocalPort int `json:"local_port"`
  30. Password string `json:"password"`
  31. Method string `json:"method"`
  32. Timeout int `json:"timeout"`
  33. }
  34.  
  35. func main() {
  36.  
  37. configFile, err := os.Open("config.json")
  38. defer configFile.Close()
  39. if err != nil {
  40. log.Fatal(err)
  41. }
  42.  
  43. jsonParser := json.NewDecoder(configFile)
  44.  
  45. if err = jsonParser.Decode(&settings); err != nil {
  46. log.Fatal("parsing config file", err.Error())
  47. }
  48.  
  49. server := fmt.Sprintf("%s:%d", settings.Server, settings.ServerPort)
  50. local := fmt.Sprintf("127.0.0.1:%d", settings.LocalPort)
  51. var key []byte
  52. ciph, err := core.PickCipher(settings.Method, key, settings.Password)
  53.  
  54. go socksLocal(local, server, ciph)
  55.  
  56. sigCh := make(chan os.Signal, 1)
  57. signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
  58. <-sigCh
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement