Exemplo n.º 1
0
// This function blocks. Run in goroutine.
func RunRelay(port int, keyhash string, isexit bool) {
	ISRELAY = true
	ieflag := 0
	if isexit {
		ieflag = 1
	}
	RefreshDirectory()
	url := fmt.Sprintf("%s/upload?port=%d&protocol=%d&keyhash=%s&exit=%d",
		DIRADDR,
		port, PROTVER, keyhash, ieflag)
	r, e := http.Get(url)
	log.Debug(url)
	time.Sleep(time.Second)
	if e != nil {
		log.Errorf("Error encountered in info upload: %s", e.Error())
		r.Body.Close()
		panic("WTF")
	}
	for {
		time.Sleep(time.Second)
		r, e := http.Get(fmt.Sprintf("%s/longpoll", DIRADDR))
		if e != nil {
			log.Errorf("Error encountered in long poll: %s", e.Error())
		retry:
			url := fmt.Sprintf("%s/upload?port=%d&protocol=%d&keyhash=%s&exit=%d",
				DIRADDR,
				port, PROTVER, keyhash, ieflag)
			log.Debug("Now of retry....")
			_, e := http.Get(url)
			log.Debug(url)
			if e != nil {
				log.Errorf("Error encountered in info upload: %s", e.Error())
				goto retry
			}
			continue
		}
		buff := new(bytes.Buffer)
		io.Copy(buff, r.Body)
		protector.Lock()
		err := json.Unmarshal(buff.Bytes(), &KDirectory)
		protector.Unlock()
		if err != nil {
			log.Errorf("Error encountered when decoding long poll: %s / %s",
				err.Error(), string(buff.Bytes()))
			r.Body.Close()
		retryy:
			url := fmt.Sprintf("%s/upload?port=%d&protocol=%d&keyhash=%s&exit=%d",
				DIRADDR,
				port, PROTVER, keyhash, ieflag)
			log.Debug("Now of retry....")
			_, e := http.Get(url)
			log.Debug(url)
			if e != nil {
				log.Errorf("Error encountered in info upload: %s", e.Error())
				goto retryy
			}
			continue
		}
	}
}
Exemplo n.º 2
0
func init() {
	err := gcfg.ReadFileInto(&MasterConfig, "kirisurf.conf")
	log.Debug("Read configuration successfully")
	if err != nil {
		panic(err.Error())
	}
}
// Fixes duplicates
func FixDuplicates(thing []int) []int {
	log.Debug(thing)
	toret := make([]int, 0)
	for i := 0; i < len(thing); i++ {
		blah := false
		for j := 0; j < len(toret); j++ {
			if toret[j] == thing[i] {
				blah = true
			}
		}
		if !blah {
			toret = append(toret, thing[i])
		}
	}
	log.Debug(toret)
	return toret
}
Exemplo n.º 4
0
func sc_server_handler(wire net.Conn) error {
	defer wire.Close()
	owire, err := kiss.Kiriobfs_handshake_server(wire)
	if err != nil {
		//log.Error(err.Error())
		return err
	}
	log.Debug("Of dones for obfs layer")
	awire, err := kiss.KiSS_handshake_server(owire, MasterKey)
	if err != nil {
		//log.Error(err.Error())
		return err
	}
	log.Debug("Of dones in kiss layer")
	// Now awire is the wire
	cmd, err := read_sc_message(awire)
	if err != nil {
		log.Error(err.Error())
		return err
	}
	log.Debug(cmd)
	if cmd.Msg_type == SC_EXTEND {
		theirnode := dirclient.PKeyLookup(cmd.Msg_arg)
		if theirnode == nil {
			return errors.New("Watif")
		}
		actwire, err := net.Dial("tcp", theirnode.Address)
		if err != nil {
			return err
		}
		remwire, err := kiss.Kiriobfs_handshake_client(actwire)
		if err != nil {
			return err
		}
		go func() {
			io.Copy(remwire, awire)
			remwire.Close()
		}()
		io.Copy(awire, remwire)
		awire.Close()
	} else if cmd.Msg_type == SC_TERMINATE && MasterConfig.General.IsExit {
		e2e_server_handler(newGobWire(awire))
	}
	return nil
}