func (pipe *spipeData) Run() {
	if pipe.Type == "enc" {
		s, _ := net.Listen("tcp", ":"+pipe.LocalPort)

		for {
			c, _ := s.Accept()
			t, _ := spipe.Dial(pipe.key, "tcp", pipe.TargetDest)
			go pipe.handleCopy(c, t)
		}
	} else {
		s, _ := spipe.Listen(pipe.key, "tcp", ":"+pipe.LocalPort)

		for {
			c, _ := s.Accept()
			t, _ := net.Dial("tcp", pipe.TargetDest)
			go pipe.handleCopy(c, t)
		}
	}
}
Exemple #2
0
func (a *app) Start(s service.Service) error {
	var err error
	var listen net.Listener

	listenOn := fmt.Sprintf(":%d", config.LocalPort)

	if len(config.KeyFile) != 0 {
		var key []byte
		key, err = ioutil.ReadFile(config.KeyFile)
		if err != nil {
			return err
		}
		listen, err = spipe.Listen(key, "tcp", listenOn)
	} else {
		listen, err = net.Listen("tcp", listenOn)
	}
	if err != nil {
		return err
	}
	log.Infof("Listening on %q", listenOn)
	go a.run(listen)
	return nil
}