コード例 #1
0
ファイル: api_test.go プロジェクト: kyonetca/emp
func TestHandshake(t *testing.T) {
	config := initialize()

	var frame quibit.Frame
	var err error

	// Test Version
	frame = *objects.MakeFrame(objects.VERSION, objects.REQUEST, &config.LocalVersion)
	frame.Peer = "127.0.0.1:4444"

	config.RecvQueue <- frame

	frame = <-config.SendQueue

	if frame.Header.Command != objects.VERSION || frame.Header.Type != objects.REPLY {
		fmt.Println("Frame is not a proper reply to a version request: ", frame.Header)
		t.FailNow()
	}

	version := new(objects.Version)
	err = version.FromBytes(frame.Payload)
	if err != nil {
		fmt.Println("Error parsing version reply: ", err)
		t.FailNow()
	}

	// Test Peer
	frame = *objects.MakeFrame(objects.PEER, objects.REQUEST, &config.NodeList)
	frame.Peer = "127.0.0.1:4444"

	config.RecvQueue <- frame

	frame = <-config.SendQueue

	if frame.Header.Command != objects.PEER || frame.Header.Type != objects.REPLY || frame.Header.Length != 0 {
		fmt.Println("Frame is not a proper reply to a peer request: ", frame.Header)
		t.FailNow()
	}

	// Test Obj
	frame = *objects.MakeFrame(objects.OBJ, objects.REQUEST, &config.NodeList)
	frame.Peer = "127.0.0.1:4444"

	config.RecvQueue <- frame

	frame = <-config.SendQueue

	if frame.Header.Command != objects.OBJ || frame.Header.Type != objects.REPLY || frame.Header.Length != 0 {
		fmt.Println("Frame is not a proper reply to a peer request: ", frame.Header)
		t.FailNow()
	}

	cleanup(config)
}
コード例 #2
0
ファイル: interface.go プロジェクト: dcposch/emp
// Creates a new Quibit Frame reading for sending from a Serializeable Object.
func MakeFrame(command, t uint8, payload Serializer) *quibit.Frame {
	frame := new(quibit.Frame)
	frame.Configure(payload.GetBytes(), command, t)
	frame.Peer = ""

	return frame
}