package org.kne.cloud.network.klalb;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.Scanner;

import org.kne.cloud.network.KLALBProxyConfigJsonExecuter;
import org.kne.cloud.network.SocketToServiceProxy;
import org.kne.cloud.network.SocketToSocketProxy;

public class KLALBMain {

	public static void main(String[] args) throws IOException {
		System.out.println(CONST.klalb+" V"+CONST.klalbver);
		Scanner scn=new Scanner(System.in);
		
		File configJson=new File("klalbconfig.json");
		
		KLALBProxyConfigJsonExecuter kpcje=new KLALBProxyConfigJsonExecuter();
		kpcje.loadConfigJson(configJson);
		while(true) {
		String s=scn.next();
		String[]sc=s.split(" ");
		switch(sc[0]) {
		case "help":
			System.out.print("help:查看命令使用说明");
			System.out.print("state:查看线路状态");
			//System.out.println("reload:重新加载线路配置文件");
			System.out.println("reconnect:所有离线线路跳过重连等待时间立即尝试重连");
			System.out.println("stop:退出程序");
			
		break;
		case "state":
			System.out.println("状态\t上传流量\t下载流量\t上传速度\t下载速度\t延迟\t抖动\t下一次重试");
			for (Iterator<KLALBRemoteLine> iterator = kpcje.getKlalbController().getLines().iterator(); iterator.hasNext();) {
				KLALBRemoteLine hostPort =  iterator.next();
				System.out.println(hostPort .toString2());
				//System.out.println();
			}
			break;
		case "stop":
			System.exit(0);
			break;
		case "reconnect":
			kpcje.getKlalbController().reconnectImmediately();
			break;
		default:
			System.out.println("未知命令，请输入help以查询指令说明");
		}
		}
		
	}

}
