本文整理汇总了Golang中github.com/skycoin/skycoin/src/util.Now函数的典型用法代码示例。如果您正苦于以下问题:Golang Now函数的具体用法?Golang Now怎么用?Golang Now使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Now函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestSetAnnounced
func TestSetAnnounced(t *testing.T) {
ut := NewUnconfirmedTxnPool()
assert.Equal(t, len(ut.Txns), 0)
// Unknown should be safe and a noop
assert.NotPanics(t, func() {
ut.SetAnnounced(cipher.SHA256{}, util.Now())
})
assert.Equal(t, len(ut.Txns), 0)
utx := createUnconfirmedTxn()
assert.True(t, utx.Announced.IsZero())
ut.Txns[utx.Hash()] = utx
now := util.Now()
ut.SetAnnounced(utx.Hash(), now)
assert.Equal(t, ut.Txns[utx.Hash()].Announced, now)
}
开发者ID:skycoin,项目名称:skycoin,代码行数:15,代码来源:unconfirmed_test.go
示例2: RecordTxn
// Adds a coin.Transaction to the pool, or updates an existing one's timestamps
// Returns an error if txn is invalid, and whether the transaction already
// existed in the pool.
func (self *UnconfirmedTxnPool) RecordTxn(bc *coin.Blockchain,
t coin.Transaction, addrs map[cipher.Address]byte, maxSize int,
burnFactor uint64) (error, bool) {
if err := VerifyTransaction(bc, &t, maxSize, burnFactor); err != nil {
return err, false
}
if err := bc.VerifyTransaction(t); err != nil {
return err, false
}
// Update if we already have this txn
h := t.Hash()
ut, ok := self.Txns[h]
if ok {
now := util.Now()
ut.Received = now
ut.Checked = now
self.Txns[h] = ut
return nil, true
}
// Add txn to index
self.Txns[h] = self.createUnconfirmedTxn(&bc.Unspent, t, addrs)
// Add predicted unspents
self.Unspent[h] = coin.CreateUnspents(bc.Head().Head, t)
return nil, false
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:31,代码来源:unconfirmed.go
示例3: InjectTxn
// InjectTxn adds a coin.Transaction to the pool, or updates an existing one's timestamps
// Returns an error if txn is invalid, and whether the transaction already
// existed in the pool.
func (utp *UnconfirmedTxnPool) InjectTxn(bc *Blockchain,
t coin.Transaction) (error, bool) {
if err := t.Verify(); err != nil {
return err, false
}
if err := VerifyTransactionFee(bc, &t); err != nil {
return err, false
}
if err := bc.VerifyTransaction(t); err != nil {
return err, false
}
// Update if we already have this txn
h := t.Hash()
ut, ok := utp.Txns[h]
if ok {
now := util.Now()
ut.Received = now
ut.Checked = now
utp.Txns[h] = ut
return nil, true
}
// Add txn to index
unspent := bc.GetUnspent()
utp.Txns[h] = utp.createUnconfirmedTxn(unspent, t)
// Add predicted unspents
utp.Unspent[h] = coin.CreateUnspents(bc.Head().Head, t)
return nil, false
}
开发者ID:skycoin,项目名称:skycoin,代码行数:36,代码来源:unconfirmed.go
示例4: RecordTxn
// Adds a coin.Transaction to the pool, or updates an existing one's timestamps
// Returns an error if txn is invalid, and whether the transaction already
// existed in the pool.
func (self *UnconfirmedTxnPool) RecordTxn(bc *coin.Blockchain,
t coin.Transaction, addrs map[coin.Address]byte, maxSize int,
burnFactor uint64) (error, bool) {
if err := VerifyTransaction(bc, &t, maxSize, burnFactor); err != nil {
return err, false
}
if err := bc.VerifyTransaction(t); err != nil {
return err, false
}
// Update if we already have this txn
ut, ok := self.Txns[t.Hash()]
if ok {
now := util.Now()
ut.Received = now
ut.Checked = now
self.Txns[ut.Txn.Hash()] = ut
return nil, true
}
// Add txn to index
self.Txns[t.Hash()] = self.createUnconfirmedTxn(&bc.Unspent, t, addrs)
// Add predicted unspents
uxs := coin.CreateExpectedUnspents(t)
for i, _ := range uxs {
self.Unspent.Add(uxs[i])
}
return nil, false
}
开发者ID:up4k,项目名称:skycoin,代码行数:33,代码来源:unconfirmed.go
示例5: 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
示例6: main
func main() {
flag.Parse()
if len(*host) == 0 {
log.Fatalf("Missing required -host parameter")
}
var err error
var notBefore time.Time
if len(*validFrom) == 0 {
notBefore = util.Now()
} else {
notBefore, err = time.Parse("Jan 2 15:04:05 2006", *validFrom)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to parse creation date: %v\n", err)
os.Exit(1)
}
}
err = util.GenerateCert(*certFile, *keyFile, *host, *organization, *rsaBits,
*isCA, notBefore, *validFor)
if err == nil {
fmt.Printf("Created %s and %s\n", *certFile, *keyFile)
} else {
fmt.Fprintln(os.Stderr, "Failed to create cert and key")
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:29,代码来源:cert.go
示例7: sendPings
// Send a ping if our last message sent was over pingRate ago
func (self *Pool) sendPings() {
now := util.Now()
for _, c := range self.Pool.Pool {
if c.LastSent.Add(self.Config.PingRate).Before(now) {
self.Pool.SendMessage(c, &PingMessage{})
}
}
}
开发者ID:RagnarDanneskjold,项目名称:skycoin,代码行数:9,代码来源:pool.go
示例8: clearStaleConnections
// Removes connections that have not sent a message in too long
func (self *Pool) clearStaleConnections() {
now := util.Now()
for _, c := range self.Pool.Pool {
if c.LastReceived.Add(self.Config.IdleLimit).Before(now) {
self.Pool.Disconnect(c, DisconnectIdle)
}
}
}
开发者ID:RagnarDanneskjold,项目名称:skycoin,代码行数:9,代码来源:pool.go
示例9: 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
示例10: TestGenerateCert
func TestGenerateCert(t *testing.T) {
defer os.Remove("certtest.pem")
defer os.Remove("keytest.pem")
err := GenerateCert("certtest.pem", "keytest.pem", "127.0.0.1", "org",
2048, false, util.Now(), time.Hour*24)
assert.Nil(t, err)
_, err = tls.LoadX509KeyPair("certtest.pem", "keytest.pem")
assert.Nil(t, err)
}
开发者ID:RagnarDanneskjold,项目名称:skycoin,代码行数:9,代码来源:cert_test.go
示例11: 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
示例12: 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
示例13: GetOldOwnedTransactions
// Returns transactions in which we are a party and have not been announced
// in ago duration
func (self *UnconfirmedTxnPool) GetOldOwnedTransactions(ago time.Duration) []UnconfirmedTxn {
txns := make([]UnconfirmedTxn, 0)
now := util.Now()
for _, tx := range self.Txns {
// TODO -- don't record IsOurSpend/IsOurReceive and do lookup each time?
// Slower but more correct
if (tx.IsOurSpend || tx.IsOurReceive) && now.Sub(tx.Announced) > ago {
txns = append(txns, tx)
}
}
return txns
}
开发者ID:up4k,项目名称:skycoin,代码行数:14,代码来源:unconfirmed.go
示例14: TestVisorSetAnnounced
func TestVisorSetAnnounced(t *testing.T) {
defer cleanupVisor()
vc := newMasterVisorConfig(t)
v := NewVisor(vc)
now := util.Now()
utx := addUnconfirmedTxn(v)
assert.True(t, utx.Announced.IsZero())
assert.True(t, v.Unconfirmed.Txns[utx.Hash()].Announced.IsZero())
v.SetAnnounced(utx.Hash(), now)
assert.False(t, v.Unconfirmed.Txns[utx.Hash()].Announced.IsZero())
assert.Equal(t, v.Unconfirmed.Txns[utx.Hash()].Announced, now)
}
开发者ID:keepwalking1234,项目名称:skycoin,代码行数:13,代码来源:blockchain_test.go
示例15: 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
示例16: Refresh
// Checks all unconfirmed txns against the blockchain. maxAge is how long
// we'll hold a txn regardless of whether it has been invalidated.
// checkPeriod is how often we check the txn against the blockchain.
func (self *UnconfirmedTxnPool) Refresh(bc *coin.Blockchain,
checkPeriod, maxAge time.Duration) {
now := util.Now()
toRemove := make([]coin.SHA256, 0)
for k, t := range self.Txns {
if now.Sub(t.Received) >= maxAge {
toRemove = append(toRemove, k)
} else if now.Sub(t.Checked) >= checkPeriod {
if bc.VerifyTransaction(t.Txn) == nil {
t.Checked = now
self.Txns[k] = t
} else {
toRemove = append(toRemove, k)
}
}
}
self.removeTxns(bc, toRemove)
}
开发者ID:up4k,项目名称:skycoin,代码行数:21,代码来源:unconfirmed.go
示例17: CreateCertIfNotExists
// Checks that certFile and keyFile exist and are files, and if not,
// returns a slice of errors indicating status.
// If neither certFile nor keyFile exist, they are automatically created
// for host
func CreateCertIfNotExists(host, certFile, keyFile string) []error {
// check that cert/key both exist, or dont
exist, errs := certKeyXor(certFile, keyFile)
// Automatically create a new cert if neither files exist
if !exist && len(errs) == 0 {
logger.Info("Creating certificate %s", certFile)
logger.Info("Creating key %s", keyFile)
err := util.GenerateCert(certFile, keyFile, host, "Skycoind", 2048,
false, util.Now(), 365*24*time.Hour)
if err == nil {
logger.Info("Created certificate %s for host %s", certFile, host)
logger.Info("Created key %s for host %s", keyFile, host)
} else {
errs = append(errs, err)
}
}
return errs
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:22,代码来源:cert.go
示例18: Refresh
// Refresh checks all unconfirmed txns against the blockchain. maxAge is how long
// we'll hold a txn regardless of whether it has been invalidated.
// checkPeriod is how often we check the txn against the blockchain.
func (utp *UnconfirmedTxnPool) Refresh(bc *Blockchain,
checkPeriod, maxAge time.Duration) {
now := util.Now()
var toRemove []cipher.SHA256
for k, t := range utp.Txns {
if now.Sub(t.Received) >= maxAge {
toRemove = append(toRemove, k)
} else if now.Sub(t.Checked) >= checkPeriod {
if bc.VerifyTransaction(t.Txn) == nil {
t.Checked = now
utp.Txns[k] = t
} else {
toRemove = append(toRemove, k)
}
}
}
utp.removeTxns(bc, toRemove)
}
开发者ID:skycoin,项目名称:skycoin,代码行数:22,代码来源:unconfirmed.go
示例19: onConnect
// Called when a ConnectEvent is processed off the onConnectEvent channel
func (self *Daemon) onConnect(e ConnectEvent) {
a := e.Addr
if e.Solicited {
logger.Info("Connected to %s as we requested", a)
} else {
logger.Info("Received unsolicited connection to %s", a)
}
delete(self.pendingConnections, a)
c := self.Pool.Pool.Addresses[a]
if c == nil {
logger.Warning("While processing an onConnect event, no pool " +
"connection was found")
return
}
blacklisted := self.Peers.Peers.IsBlacklisted(a)
if blacklisted {
logger.Info("%s is blacklisted, disconnecting", a)
self.Pool.Pool.Disconnect(c, DisconnectIsBlacklisted)
return
}
if self.ipCountMaxed(a) {
logger.Info("Max connections for %s reached, disconnecting", a)
self.Pool.Pool.Disconnect(c, DisconnectIPLimitReached)
return
}
self.recordIPCount(a)
if e.Solicited {
self.OutgoingConnections[a] = c
}
self.ExpectingIntroductions[a] = util.Now()
logger.Debug("Sending introduction message to %s", a)
m := NewIntroductionMessage(self.Messages.Mirror, self.Config.Version,
self.Pool.Pool.Config.Port)
self.Pool.Pool.SendMessage(c, m)
}
开发者ID:kinghuabg,项目名称:skycoin,代码行数:43,代码来源:daemon.go
示例20: cullInvalidConnections
// Removes unsolicited connections who haven't sent a version
func (self *Daemon) cullInvalidConnections() {
// This method only handles the erroneous people from the DHT, but not
// malicious nodes
now := util.Now()
for a, t := range self.ExpectingIntroductions {
// Forget about anyone that already disconnected
if self.Pool.Pool.Addresses[a] == nil {
delete(self.ExpectingIntroductions, a)
continue
}
// Remove anyone that fails to send a version within introductionWait time
if t.Add(self.Config.IntroductionWait).Before(now) {
logger.Info("Removing %s for not sending a version", a)
delete(self.ExpectingIntroductions, a)
self.Pool.Pool.Disconnect(self.Pool.Pool.Addresses[a],
DisconnectIntroductionTimeout)
self.Peers.RemovePeer(a)
}
}
}
开发者ID:kinghuabg,项目名称:skycoin,代码行数:21,代码来源:daemon.go
注:本文中的github.com/skycoin/skycoin/src/util.Now函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论