Пример #1
0
func main() {
	// Define and parse flags.
	id := flag.Uint("id", 0, "Set the client node ID to connect to.")
	rate = flag.Uint("rate", 0, "Sets the maximum messages per second.")
	flag.Parse()

	// Validate flags.
	if *id == 0 || *id > 0xFFFF {
		log.Fatal("Invalid node ID specified.")
	}

	// Load configuration from config file.
	loadConfig()

	fmt.Printf("Loaded configuration, ID to connect to is %d.\n", *id)

	conn, err := connect.TestDial(uint16(*id))
	if err != nil {
		log.Fatal(err)
	}

	var msg cliproto_up.Authenticate
	msg.Username = new(string)
	msg.Password = new(string)
	msg.SessionId = new(uint64)
	*msg.Username = "******"
	*msg.Password = "******"
	conn.SendProto(2, &msg)

	for {
		respMsg, ok := <-conn.Received
		if !ok {
			log.Fatal("connection error")
		}

		switch *respMsg.MsgType {
		case 2:
			conn.Close()
			log.Fatal("auth failed")
		case 3:
			log.Print("authenticated, follow msgsink...")

			var followMsg cliproto_up.FollowUsername
			followMsg.Username = new(string)
			*followMsg.Username = "******"
			conn.SendProto(3, &followMsg)
		case 4:
			log.Fatal("follow failed")
		case 6:
			handleData(respMsg.Content)
		case 7:
			log.Print("following msgsink, sending msgs...")
			go sendMessages(conn)
		}
	}
}
Пример #2
0
func main() {
	// Define and parse flags.
	id := flag.Uint("id", 0, "Set the client node ID to connect to.")
	print = flag.Uint("print", 10000, "Sets number of messages to print "+
		"after.")

	flag.Parse()

	// Validate flags.
	if *id == 0 || *id > 0xFFFF {
		log.Fatal("Invalid node ID specified.")
	}

	// Load configuration from config file.
	loadConfig()

	fmt.Printf("Loaded configuration, ID to connect to is %d.\n", *id)

	conn, err := connect.TestDial(uint16(*id))
	if err != nil {
		log.Fatal(err)
	}

	var msg cliproto_up.Authenticate
	msg.Username = new(string)
	msg.Password = new(string)
	msg.SessionId = new(uint64)
	*msg.Username = "******"
	*msg.Password = "******"
	conn.SendProto(2, &msg)

	for {
		respMsg, ok := <-conn.Received
		if !ok {
			break
			log.Fatal("connection error")
		}

		switch *respMsg.MsgType {
		case 2:
			conn.Close()
			log.Fatal("auth failed")
		case 3:
			log.Print("authenticated")
		case 10:
			handleMsg(respMsg.Content)
		}
	}
}
Пример #3
0
func register(node uint16, prefix string, limit uint, doneChan chan bool) {

	for i := uint(0); i < limit; i++ {
		conn, err := connect.TestDial(node)
		if err != nil {
			log.Fatal(err)
		}

		var msg cliproto_up.Authenticate
		msg.Username = new(string)
		msg.Password = new(string)
		msg.SessionId = new(uint64)
		*msg.Username = prefix + strconv.FormatUint(uint64(i), 10)
		*msg.Password = prefix + strconv.FormatUint(uint64(i), 10)
		conn.SendProto(2, &msg)

	connloop:
		for {
			respMsg, ok := <-conn.Received
			if !ok {
				log.Fatal("connection error to ", node)
				break connloop
			}

			switch *respMsg.MsgType {
			case 2:
				// Terminates.
				handleAuthFail(respMsg.Content)
			case 3:
				conn.Close()
				break connloop
			}
		}
	}

	doneChan <- true
}