Beispiel #1
0
func TestCodec(t *testing.T) {

	f := trace.NewFrame()
	sx := sandbox.NewUnreliableTransport(f.Refine("sandbox"), 5, 0, time.Second/3, time.Second/3)
	hx := chain.NewTransport(f.Refine("chain"), sx)
	fx := faithful.NewTransport(f.Refine("faithful"), hx)
	cx := codec.NewTransport(fx, codec.GobCodec{})
	bx := NewTransport(f.Refine("session"), cx)

	// Sync
	ya, yb := make(chan int), make(chan int)

	// Accepter
	go func() {
		as := bx.Listen(sandbox.Addr("@")).AcceptSession()
		for i := 0; i < testN; i++ {
			go testAcceptConn(t, as, ya, yb)
		}
	}()

	// Dialer
	ds := bx.DialSession(sandbox.Addr("@"), nil)
	go func() {
		for i := 0; i < testN; i++ {
			go testDialConn(t, ds, ya, yb)
		}
	}()

	for i := 0; i < testN; i++ {
		<-yb
	}
}
Beispiel #2
0
func NewStructOverTCPWithHMAC(key []byte) *blend.Transport {
	f := trace.NewFrame("tele")
	// Carrier
	x2 := hmac.NewTransport(key)
	// Codec
	x3 := codec.NewTransport(x2, codec.GobCodec{})
	// Blend
	return blend.NewTransport(f.Refine("blend"), x3)
}
Beispiel #3
0
func NewStructOverTCP() *blend.Transport {
	f := trace.NewFrame("tele")
	// Carrier
	x2 := tcp.CodecTransport
	// Codec
	x3 := codec.NewTransport(x2, codec.GobCodec{})
	// Blend
	return blend.NewTransport(f.Refine("blend"), x3)
}
Beispiel #4
0
func NewStructOverTCP() *blend.Transport {
	f := trace.NewFrame("tele")
	// Carrier
	x0 := tcp.Transport
	// Chain
	x1 := chain.NewTransport(f.Refine("chain"), x0)
	// Faithful
	x2 := faithful.NewTransport(f.Refine("faithful"), x1)
	// Codec
	x3 := codec.NewTransport(x2, codec.GobCodec{})
	// Blend
	return blend.NewTransport(f.Refine("blend"), x3)
}
Beispiel #5
0
func TestClosure(t *testing.T) {
	const testK = 1

	f := trace.NewFrame()
	sx := tcp.Transport
	hx := chain.NewTransport(f.Refine("chain"), sx)
	fx := faithful.NewTransport(f.Refine("faithful"), hx)
	cx := codec.NewTransport(fx, codec.GobCodec{})
	bx := NewTransport(f.Refine("session"), cx)

	// Sync
	ya, yb := make(chan int), make(chan int)

	a, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:40090")

	// Accepter
	go func() {
		as := bx.Listen(a).AcceptSession()
		for i := 0; i < testK; i++ {
			go testAcceptConn(t, as, ya, yb)
		}
	}()

	// Dialer
	ds := bx.DialSession(a, nil)
	go func() {
		for i := 0; i < testK; i++ {
			go testDialConn(t, ds, ya, yb)
		}
	}()

	for i := 0; i < testK; i++ {
		<-yb
	}

	ds.Close()
	println("hold a minute...")
	time.Sleep(time.Minute)
	println("now check that the test process has no open tcp connections...")
	time.Sleep(time.Minute)
	println("great.")
}