当前位置: 首页>>代码示例>>Golang>>正文


Golang util.ZeroTime函数代码示例

本文整理汇总了Golang中github.com/skycoin/skycoin/src/util.ZeroTime函数的典型用法代码示例。如果您正苦于以下问题:Golang ZeroTime函数的具体用法?Golang ZeroTime怎么用?Golang ZeroTime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ZeroTime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestCullInvalidConnections

func TestCullInvalidConnections(t *testing.T) {
	d := newDefaultDaemon()
	// Is fine
	d.ExpectingIntroductions[addr] = time.Now()
	// Is expired
	d.ExpectingIntroductions[addrb] = util.ZeroTime()
	// Is not in pool
	d.ExpectingIntroductions[addrc] = util.ZeroTime()
	d.Peers.Peers.AddPeer(addr)
	d.Peers.Peers.AddPeer(addrb)
	d.Peers.Peers.AddPeer(addrc)
	d.Pool.Pool.Addresses[addr] = gnetConnection(addr)
	d.Pool.Pool.Addresses[addrb] = gnetConnection(addrb)
	d.Pool.Pool.Addresses[addrb].Id = 2
	d.Pool.Pool.Pool[1] = d.Pool.Pool.Addresses[addr]
	d.Pool.Pool.Pool[2] = d.Pool.Pool.Addresses[addrb]

	assert.NotPanics(t, d.cullInvalidConnections)

	assert.Equal(t, len(d.ExpectingIntroductions), 1)
	assert.Equal(t, len(d.Peers.Peers.Peerlist), 2)
	assert.Equal(t, len(d.Pool.Pool.DisconnectQueue), 1)
	if len(d.Pool.Pool.DisconnectQueue) == 0 {
		t.Fatal("pool.Pool.DisconnectQueue not empty, would block")
	}
	de := <-d.Pool.Pool.DisconnectQueue
	assert.Equal(t, de.ConnId, 2)
	assert.Equal(t, de.Reason, DisconnectIntroductionTimeout)
	shutdown(d)
}
开发者ID:kinghuabg,项目名称:skycoin,代码行数:30,代码来源:daemon_test.go

示例2: gnetConnection

func gnetConnection(addr string) *gnet.Connection {
	return &gnet.Connection{
		Id:           1,
		Conn:         NewDummyConn(addr),
		LastSent:     util.ZeroTime(),
		LastReceived: util.ZeroTime(),
		Buffer:       &bytes.Buffer{},
		WriteQueue:   make(chan gnet.Message, 16),
	}
}
开发者ID:up4k,项目名称:skycoin,代码行数:10,代码来源:messages_test.go

示例3: createUnconfirmedTxn

// Creates an unconfirmed transaction
func (self *UnconfirmedTxnPool) createUnconfirmedTxn(bcUnsp *coin.UnspentPool,
	t coin.Transaction, addrs map[coin.Address]byte) UnconfirmedTxn {
	now := util.Now()
	ut := UnconfirmedTxn{
		Txn:          t,
		Received:     now,
		Checked:      now,
		Announced:    util.ZeroTime(),
		IsOurReceive: false,
		IsOurSpend:   false,
	}

	// Check if this unspent is related to us
	if addrs != nil {
		// Check if this is one of our receiving txns
		for i, _ := range t.Out {
			if _, ok := addrs[t.Out[i].Address]; ok {
				ut.IsOurReceive = true
				break
			}
		}
		// Check if this is one of our spending txns
		for i, _ := range t.In {
			if ux, ok := bcUnsp.Get(t.In[i]); ok {
				if _, ok := addrs[ux.Body.Address]; ok {
					ut.IsOurSpend = true
					break
				}
			}
		}
	}

	return ut
}
开发者ID:up4k,项目名称:skycoin,代码行数:35,代码来源:unconfirmed.go

示例4: TestGetPeersMessage

func TestGetPeersMessage(t *testing.T) {
	d := newDefaultDaemon()
	defer shutdown(d)
	p := d.Pool
	m := NewGetPeersMessage()
	testSimpleMessageHandler(t, d, m)
	d.Peers.Peers.AddPeer(addr)
	q, err := d.Peers.Peers.AddPeer(addrb)
	assert.Nil(t, err)
	q.Private = true
	d.Peers.Config.ReplyCount = 100
	m.c = messageContext(addr)

	// Peers disabled
	d.Peers.Config.Disabled = true
	assert.NotPanics(t, func() { m.Process(d) })
	wait()
	assert.Equal(t, len(p.Pool.SendResults), 0)
	assert.True(t, m.c.Conn.LastSent.IsZero())

	// Peers enabled
	d.Peers.Config.Disabled = false
	m.c = messageContext(addr)
	defer m.c.Conn.Close()
	go p.Pool.ConnectionWriteLoop(m.c.Conn)
	assert.NotPanics(t, func() { m.Process(d) })
	wait()
	assert.Equal(t, len(p.Pool.SendResults), 1)
	if len(p.Pool.SendResults) == 0 {
		t.Fatal("SendResults empty, would block")
	}
	sr := <-p.Pool.SendResults
	assert.Nil(t, sr.Error)
	assert.Equal(t, sr.Connection, m.c.Conn)
	msg, ok := sr.Message.(*GivePeersMessage)
	assert.True(t, ok)
	// Private peer should not be included
	ipAddr, err := NewIPAddr(addr)
	assert.Nil(t, err)
	assert.Equal(t, msg.Peers, []IPAddr{ipAddr})
	assert.False(t, m.c.Conn.LastSent.IsZero())

	// If no peers, nothing should happen
	m.c.Conn.LastSent = util.ZeroTime()
	delete(d.Peers.Peers.Peerlist, addr)
	assert.NotPanics(t, func() { m.Process(d) })
	wait()
	assert.Equal(t, len(p.Pool.SendResults), 0)
	assert.True(t, m.c.Conn.LastSent.IsZero())

	// Test serialization
	m = NewGetPeersMessage()
	b := encoder.Serialize(m)
	m2 := GetPeersMessage{}
	assert.Nil(t, encoder.DeserializeRaw(b, &m2))
	assert.Equal(t, *m, m2)

	gnet.EraseMessages()
}
开发者ID:Chao-Jia,项目名称:skycoin,代码行数:59,代码来源:messages_test.go

示例5: createUnconfirmedTxn

func createUnconfirmedTxn() UnconfirmedTxn {
	ut := UnconfirmedTxn{}
	ut.Txn = coin.Transaction{}
	ut.Txn.Head.Hash = randSHA256()
	ut.Received = util.Now()
	ut.Checked = ut.Received
	ut.Announced = util.ZeroTime()
	return ut
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:9,代码来源:readable_test.go

示例6: createUnconfirmedTxn

// Creates an unconfirmed transaction
func (utp *UnconfirmedTxnPool) createUnconfirmedTxn(bcUnsp *coin.UnspentPool,
	t coin.Transaction) UnconfirmedTxn {
	now := util.Now()
	return UnconfirmedTxn{
		Txn:       t,
		Received:  now,
		Checked:   now,
		Announced: util.ZeroTime(),
	}
}
开发者ID:skycoin,项目名称:skycoin,代码行数:11,代码来源:unconfirmed.go

示例7: testDaemonLoopClearOldPeersTicker

func testDaemonLoopClearOldPeersTicker(t *testing.T, d *Daemon, quit chan int,
	count int) {
	p := pex.NewPeer(addr)
	p.LastSeen = util.ZeroTime()
	d.Peers.Peers.Peerlist[addr] = p
	d.Peers.Config.CullRate = time.Millisecond * 10
	go d.Start(quit)
	time.Sleep(time.Millisecond * 15)
	assert.Equal(t, len(d.Peers.Peers.Peerlist), count)
}
开发者ID:kinghuabg,项目名称:skycoin,代码行数:10,代码来源:daemon_test.go

示例8: testDaemonLoopClearStaleConnectionsTicker

func testDaemonLoopClearStaleConnectionsTicker(t *testing.T, d *Daemon,
	quit chan int, poolCount int) {
	c := gnetConnection(addr)
	c.LastReceived = util.ZeroTime()
	d.Pool.Pool.Pool[c.Id] = c
	d.Pool.Config.ClearStaleRate = time.Millisecond * 10
	go d.Start(quit)
	time.Sleep(time.Millisecond * 15)
	assert.Equal(t, len(d.Pool.Pool.Pool), poolCount)
}
开发者ID:kinghuabg,项目名称:skycoin,代码行数:10,代码来源:daemon_test.go

示例9: createUnconfirmedTxn

// Creates an unconfirmed transaction
func (self *UnconfirmedTxnPool) createUnconfirmedTxn(bcUnsp *coin.UnspentPool,
	t coin.Transaction, addrs map[coin.Address]byte) UnconfirmedTxn {
	now := util.Now()
	return UnconfirmedTxn{
		Txn:       t,
		Received:  now,
		Checked:   now,
		Announced: util.ZeroTime(),
	}
}
开发者ID:kinghuabg,项目名称:skycoin,代码行数:11,代码来源:unconfirmed.go

示例10: createUnconfirmedTxn

func createUnconfirmedTxn() visor.UnconfirmedTxn {
	now := util.Now()
	return visor.UnconfirmedTxn{
		Txn: coin.Transaction{
			Head: coin.TransactionHeader{
				Hash: coin.SumSHA256([]byte("cascas")),
			},
		},
		Received:  now,
		Checked:   now,
		Announced: util.ZeroTime(),
	}
}
开发者ID:notsoshifty,项目名称:skycoin,代码行数:13,代码来源:visor_test.go

示例11: TestAnnounceTxnsMessageProcess

func TestAnnounceTxnsMessageProcess(t *testing.T) {
	v, _ := setupVisor()
	d, _ := newVisorDaemon(v)
	defer shutdown(d)
	gc := setupExistingPool(d.Pool)
	go d.Pool.Pool.ConnectionWriteLoop(gc)

	tx := createUnconfirmedTxn()
	txns := []coin.SHA256{tx.Txn.Hash()}
	m := NewAnnounceTxnsMessage(txns)
	m.c = messageContext(addr)
	go d.Pool.Pool.ConnectionWriteLoop(m.c.Conn)
	defer m.c.Conn.Close()

	// Disabled, nothing should happen
	d.Visor.Config.Disabled = true
	assert.NotPanics(t, func() { m.Process(d) })
	wait()
	assert.Equal(t, len(d.Pool.Pool.SendResults), 0)
	assert.True(t, m.c.Conn.LastSent.IsZero())
	assert.True(t, gc.LastSent.IsZero())

	// We don't know some, request them
	d.Visor.Config.Disabled = false
	assert.NotPanics(t, func() { m.Process(d) })
	wait()
	assert.Equal(t, len(d.Pool.Pool.SendResults), 1)
	if len(d.Pool.Pool.SendResults) == 0 {
		t.Fatal("SendResults empty, would block")
	}
	sr := <-d.Pool.Pool.SendResults
	assert.Equal(t, sr.Connection, m.c.Conn)
	assert.Nil(t, sr.Error)
	_, ok := sr.Message.(*GetTxnsMessage)
	assert.True(t, ok)
	assert.False(t, m.c.Conn.LastSent.IsZero())
	// Should not have been broadcast
	assert.True(t, gc.LastSent.IsZero())

	// We know all the reported txns, nothing should be sent
	d.Visor.Visor.Unconfirmed.Txns[tx.Txn.Hash()] = tx
	m.c.Conn.Conn = NewDummyConn(addr)
	m.c.Conn.LastSent = util.ZeroTime()
	assert.NotPanics(t, func() { m.Process(d) })
	wait()
	assert.Equal(t, len(d.Pool.Pool.SendResults), 0)
	assert.True(t, m.c.Conn.LastSent.IsZero())
	assert.True(t, gc.LastSent.IsZero())
}
开发者ID:up4k,项目名称:skycoin,代码行数:49,代码来源:visor_test.go

示例12: TestVisorRequestBlocksFromAddr

func TestVisorRequestBlocksFromAddr(t *testing.T) {
	defer cleanupVisor()
	defer gnet.EraseMessages()
	p, gc := setupPool()
	vc, _ := setupVisor()
	go p.Pool.ConnectionWriteLoop(gc)

	// Disabled
	vc.Disabled = true
	v := NewVisor(vc)
	assert.NotPanics(t, func() {
		err := v.RequestBlocksFromAddr(p, addr)
		assert.NotNil(t, err)
		assert.Equal(t, err.Error(), "Visor disabled")
	})
	wait()
	assert.Equal(t, len(p.Pool.SendResults), 0)
	assert.True(t, gc.LastSent.IsZero())

	vc.Disabled = false
	v = NewVisor(vc)
	assert.NotPanics(t, func() {
		assert.Nil(t, v.RequestBlocksFromAddr(p, addr))
	})
	wait()
	assert.Equal(t, len(p.Pool.SendResults), 1)
	if len(p.Pool.SendResults) == 0 {
		t.Fatal("SendResults empty, would block")
	}
	sr := <-p.Pool.SendResults
	assert.Nil(t, sr.Error)
	assert.Equal(t, sr.Connection, gc)
	_, ok := sr.Message.(*GetBlocksMessage)
	assert.True(t, ok)
	assert.False(t, gc.LastSent.IsZero())

	// No connection found for addr
	gc.LastSent = util.ZeroTime()
	gc.Conn = NewDummyConn(addr)
	delete(p.Pool.Pool, gc.Id)
	delete(p.Pool.Addresses, gc.Addr())
	assert.NotPanics(t, func() {
		assert.NotNil(t, v.RequestBlocksFromAddr(p, addr))
	})
	wait()
	assert.Equal(t, len(p.Pool.SendResults), 0)
	assert.True(t, gc.LastSent.IsZero())
}
开发者ID:up4k,项目名称:skycoin,代码行数:48,代码来源:visor_test.go

示例13: testDaemonLoopPingCheckTicker

func testDaemonLoopPingCheckTicker(t *testing.T, d *Daemon, quit chan int,
	sent bool) {
	c := gnetConnection(addr)
	go d.Pool.Pool.ConnectionWriteLoop(c)
	c.LastSent = util.ZeroTime()
	d.Pool.Pool.Pool[c.Id] = c
	d.Pool.Config.IdleCheckRate = time.Millisecond * 10
	go d.Start(quit)
	time.Sleep(time.Millisecond * 15)
	if sent {
		assert.False(t, c.LastSent.IsZero())
	} else {
		assert.True(t, c.LastSent.IsZero())
	}
	c.Close()
	wait()
}
开发者ID:kinghuabg,项目名称:skycoin,代码行数:17,代码来源:daemon_test.go

示例14: TestClearStaleConnections

func TestClearStaleConnections(t *testing.T) {
	dm := newDefaultDaemon()
	defer shutdown(dm)
	c := gnetConnection(addr)
	d := gnetConnection(addrb)
	c.LastReceived = util.ZeroTime()
	d.LastReceived = time.Now()
	dm.Pool.Pool.Pool[1] = c
	dm.Pool.Pool.Pool[2] = d
	assert.NotPanics(t, dm.Pool.clearStaleConnections)
	assert.Equal(t, len(dm.Pool.Pool.DisconnectQueue), 1)
	if len(dm.Pool.Pool.DisconnectQueue) == 0 {
		t.Fatalf("Empty DisconnectQueue, would block")
	}
	de := <-dm.Pool.Pool.DisconnectQueue
	assert.Equal(t, de.ConnId, 1)
	assert.Equal(t, de.Reason, DisconnectIdle)
}
开发者ID:kinghuabg,项目名称:skycoin,代码行数:18,代码来源:daemon_test.go

示例15: TestOnConnect

func TestOnConnect(t *testing.T) {
	d := newDefaultDaemon()

	// Test a valid connection, unsolicited
	e := ConnectEvent{addr, false}
	p, _ := d.Peers.Peers.AddPeer(addr)
	c := setupExistingPool(d.Pool)
	go d.Pool.Pool.ConnectionWriteLoop(c)
	d.pendingConnections[addr] = p
	assert.NotPanics(t, func() { d.onConnect(e) })
	wait()
	assert.Equal(t, len(d.Pool.Pool.SendResults), 1)
	if len(d.Pool.Pool.SendResults) == 0 {
		t.Fatalf("SendResults empty, would block")
	}
	sr := <-d.Pool.Pool.SendResults
	assert.Equal(t, sr.Connection, c)
	assert.Nil(t, sr.Error)
	_, ok := sr.Message.(*IntroductionMessage)
	assert.True(t, ok)
	// This connection should no longer be pending
	assert.Equal(t, len(d.pendingConnections), 0)
	// This is not an outgoing connection, we did not solicit it
	assert.Equal(t, len(d.OutgoingConnections), 0)
	// We should be expecting its version
	assert.Equal(t, len(d.ExpectingIntroductions), 1)
	_, exists := d.ExpectingIntroductions[addr]
	assert.True(t, exists)
	// An introduction should have been sent
	assert.False(t, c.LastSent.IsZero())
	// d.ipCounts should be 1
	assert.Equal(t, d.ipCounts[addrIP], 1)
	// Cleanup
	delete(d.ipCounts, addrIP)
	delete(d.ExpectingIntroductions, addr)
	c.Close()

	// Test a valid connection, solicited
	e = ConnectEvent{addr, true}
	c = gnetConnection(addr)
	go d.Pool.Pool.ConnectionWriteLoop(c)
	d.pendingConnections[addr] = p
	d.Pool.Pool.Addresses[addr] = c
	d.Pool.Pool.Pool[c.Id] = c
	assert.NotPanics(t, func() { d.onConnect(e) })
	wait()
	assert.Equal(t, len(d.Pool.Pool.SendResults), 1)
	if len(d.Pool.Pool.SendResults) == 0 {
		t.Fatalf("SendResults empty, would block")
	}
	sr = <-d.Pool.Pool.SendResults
	assert.Equal(t, sr.Connection, c)
	assert.Nil(t, sr.Error)
	_, ok = sr.Message.(*IntroductionMessage)
	assert.True(t, ok)
	// This connection should no longer be pending
	assert.Equal(t, len(d.pendingConnections), 0)
	// We should mark this as an outgoing connection since we solicited it
	assert.Equal(t, len(d.OutgoingConnections), 1)
	assert.NotNil(t, d.OutgoingConnections[addr])
	// We should be expecting its version
	assert.Equal(t, len(d.ExpectingIntroductions), 1)
	_, exists = d.ExpectingIntroductions[addr]
	assert.True(t, exists)
	// An introduction should have been sent
	assert.False(t, c.LastSent.IsZero())
	// d.ipCounts should be 1
	assert.Equal(t, d.ipCounts[addrIP], 1)
	// Cleanup
	c.Close()
	delete(d.ExpectingIntroductions, addr)
	delete(d.OutgoingConnections, addr)
	delete(d.ipCounts, addrIP)

	// Test a connection that is not connected by the time of processing
	c.LastSent = util.ZeroTime()
	e = ConnectEvent{addr, true}
	delete(d.Pool.Pool.Addresses, addr)
	d.pendingConnections[addr] = p
	assert.NotPanics(t, func() { d.onConnect(e) })
	wait()
	assert.Equal(t, len(d.Pool.Pool.SendResults), 0)
	// This connection should no longer be pending
	assert.Equal(t, len(d.pendingConnections), 0)
	// No message should have been sent
	assert.True(t, c.LastSent.IsZero())
	// We should not be expecting its version
	assert.Equal(t, len(d.ExpectingIntroductions), 0)
	// We should not have recorded it to ipCount
	assert.Equal(t, d.ipCounts[addrIP], 0)

	// Test a connection that is blacklisted
	e = ConnectEvent{addr, true}
	c = gnetConnection(addr)
	go d.Pool.Pool.ConnectionWriteLoop(c)
	d.Peers.Peers.AddBlacklistEntry(addr, time.Hour)
	d.pendingConnections[addr] = p
	d.Pool.Pool.Addresses[addr] = c
	d.Pool.Pool.Pool[c.Id] = c
	assert.NotPanics(t, func() { d.onConnect(e) })
//.........这里部分代码省略.........
开发者ID:kinghuabg,项目名称:skycoin,代码行数:101,代码来源:daemon_test.go


注:本文中的github.com/skycoin/skycoin/src/util.ZeroTime函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。