Esempio n. 1
0
func NewServer(d5s *D5ServConf, dhKey crypto.DHKE) *Server {
	s := &Server{
		D5ServConf: d5s,
		dhKey:      dhKey,
		sharedKey:  d5s.rsaKey.SharedKey(),
		sessionMgr: NewSessionMgr(),
		tunParams: &tunParams{
			pingInterval: DT_PING_INTERVAL,
			parallels:    PARALLEL_TUN_QTY,
		},
	}

	// inital update time counter
	s.updateNow()

	var step = time.Second * TIME_STEP
	var now = time.Now()
	// Calculate the distance to next integral minute,
	var dis = now.Truncate(step).Add(step).Sub(now).Nanoseconds() - 1e3
	if dis < 1e3 {
		dis = 1e3
	}

	// To make the discrete time-counter closer to the exact zero point of minute.
	// then plan starting the timer on next integral minutes.
	time.AfterFunc(time.Duration(dis), func() {
		s.updateNow() // first run on integral point manully
		go s.updateTimeCounterWorker(step)
	})

	if len(d5s.DenyDest) == 2 {
		s.filter, _ = geo.NewGeoIPFilter(d5s.DenyDest)
	}
	return s
}
Esempio n. 2
0
func NewServer(cman *ConfigMan) *Server {
	conf := cman.sConf
	s := &Server{
		serverConf: conf,
		sharedKey:  preSharedKey(conf.publicKey),
		sessionMgr: NewSessionMgr(),
		tunParams: &tunParams{
			pingInterval: DT_PING_INTERVAL,
			parallels:    conf.Parallels,
		},
	}

	// inital update time counter
	s.updateNow()

	var step = time.Second * TIME_STEP
	var now = time.Now()
	// Calculate the distance to next integral minute,
	var dis = now.Truncate(step).Add(step).Sub(now).Nanoseconds() - 1e3
	if dis < 1e3 {
		dis = 1e3
	}

	// To make the discrete time-counter closer to the exact zero point of minute.
	// then plan starting the timer on next integral minutes.
	time.AfterFunc(time.Duration(dis), func() {
		s.updateNow() // first run on integral point manully
		go s.updateTimeCounterWorker(step)
	})

	if len(conf.DenyDest) == 2 {
		s.filter, _ = geo.NewGeoIPFilter(conf.DenyDest)
	}
	return s
}
Esempio n. 3
0
func NewServer(d5s *D5ServConf, dhKeys *DHKeyPair) *Server {
	s := &Server{d5s, dhKeys, NewSessionMgr(), nil}
	if len(d5s.DenyDest) == 2 {
		s.filter, _ = geo.NewGeoIPFilter(d5s.DenyDest)
	}
	return s
}