Exemplo n.º 1
0
func GetUpstream(hostname string) (upstream *Upstream, err *mcchat.ChatMsg) {
	config_lock.Lock()
	defer config_lock.Unlock()
	log.Debugf("hostname=%s", hostname)
	for _, u := range config.Upstream {
		log.Debugf("pattern=%s", u.Pattern)
		if matched, _ := path.Match(u.Pattern, hostname); matched {
			log.Infof("matched server: %s", u.Server)
			return u, nil
		}
	}
	log.Warnf("no match for %s", hostname)
	return nil, config.chatNotFound
}
Exemplo n.º 2
0
func PostLoadConfig() {
	for p, l := range postLoadConfigHandlers {
		if l == nil {
			continue
		}
		log.Debugf("Calling PostLoadConfig priority=%d", p)
		for _, handler := range l {
			handler()
		}
	}
}
Exemplo n.º 3
0
func heartBeatTicker() {
	for {
		time.Sleep(time.Second * time.Duration(delta))
		if limit == 0 {
			continue
		}
		ctlock.Lock()
		log.Infof("[conntrack] Reducing connection count...")
		for track := range conn_track {
			if conn_track[track] <= limit {
				delete(conn_track, track)
				log.Debugf("[conntrack] Removing IP %s.", track)
			} else {
				conn_track[track] -= limit
			}

		}
		log.Infof("[conntrack] Done. IPs currently in record: %d", len(conn_track))
		ctlock.Unlock()
	}
}
Exemplo n.º 4
0
func (upstream *Upstream) GetExtra(path string) (val interface{}, err error) {
	defer func() {
		if r := recover(); r != nil {
			log.Errorf("Recovered panic: upstream.GetExtra(%s), err=%+v", path, r)
			log.Debugf("Upstream: %+v", upstream)
			val = nil
			err = errors.New("panic when getting config.")
			return
		}
	}()
	paths := strings.Split(path, ".")
	cur := reflect.ValueOf(upstream.Extras)
	// ROOT can't be an array, so assume no config path starts with #
	for _, path := range paths {
		index := strings.Split(path, "#")
		prefix, index := index[0], index[1:]
		if cur.Kind() != reflect.Map {
			log.Warnf("upstream.GetExtra(%s): unable to fetch key %s, not a map.", path, prefix)
			return nil, fmt.Errorf("index key on non-map type")
		}
		cur = reflect.ValueOf(cur.MapIndex(reflect.ValueOf(prefix)).Interface())
		for _, idx := range index {
			i, err := strconv.ParseInt(idx, 0, 0)
			if err != nil {
				log.Errorf("upstream.GetExtra(%s): unable to parse %s: %s", path, idx, err.Error())
				return nil, fmt.Errorf("Unable to parse %s: %s", idx, err.Error())
			}
			if cur.Kind() != reflect.Slice {
				log.Warnf("upstream.GetExtra(%s): unable to index value, not a slice", path)
				return nil, errors.New("Unable to index value, not a slice.")
			}
			if int(i) >= cur.Len() {
				log.Warnf("upstream.GetExtra(%s): index %d out of range", path, i)
				return nil, errors.New("Index out of range.")
			}
			cur = reflect.ValueOf(cur.Index(int(i)).Interface())
		}
	}
	return cur.Interface(), nil
}
Exemplo n.º 5
0
func (event *NetworkEvent) Debugf(format string, v ...interface{}) {
	if event.log_prefix == "" {
		event.log_prefix = fmt.Sprintf("[#%d %s]", event.connID, event.RemoteAddr)
	}
	log.Debugf(event.log_prefix+format, v...)
}
Exemplo n.º 6
0
func (ws *WrapedSocket) Debugf(format string, v ...interface{}) {
	log.Debugf(ws.log_prefix+format, v...)
}