本文整理汇总了Golang中github.com/tanuki-ipfs/core/log.Println函数的典型用法代码示例。如果您正苦于以下问题:Golang Println函数的具体用法?Golang Println怎么用?Golang Println使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Println函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updateLink
func (t *Thread) updateLink(n *merkledag.Node, stamp time.Time) func(bool, *merkledag.Node) (bool, error) {
return func(exist bool, prev *merkledag.Node) (bool, error) {
if exist {
return false, nil
}
pren, err := getLinkName(prev)
if log.If(err) {
return false, err
}
if pren != nil {
log.Println(pren.stamp)
pn := pren.string()
raw, errr := prev.GetNodeLink(pn)
if log.If(errr) {
return false, errr
}
if errr := n.AddRawLink(pn, raw); log.If(errr) {
return false, errr
}
if errr := prev.RemoveNodeLink(pn); log.If(errr) {
return false, errr
}
}
name := &linkName{stamp: stamp}
log.Println(name.stamp)
if err := prev.AddNodeLink(name.string(), n); log.If(err) {
return false, err
}
log.If(err)
return true, err
}
}
示例2: doInit
func doInit(out io.Writer, repoRoot string, force bool, empty bool, nBitsForKeypair int) error {
log.Println("initializing ipfs node at ", repoRoot)
if err := checkWriteable(repoRoot); err != nil {
return err
}
if fsrepo.IsInitialized(repoRoot) && !force {
log.Println("repo already exists")
return nil
}
conf, err := config.Init(out, nBitsForKeypair)
if err != nil {
return err
}
if fsrepo.IsInitialized(repoRoot) {
if err := fsrepo.Remove(repoRoot); err != nil {
return err
}
}
if err := fsrepo.Init(repoRoot, conf); err != nil {
return err
}
if !empty {
if err := addDefaultAssets(out, repoRoot); err != nil {
return err
}
}
return initializeIpnsKeyspace(repoRoot)
}
示例3: Slice
//Slice returns sorted records slice.
//if insufficient number it returns atmost records slice.
func (t *Thread) Slice(from, to int, spam slice.Key) (record.Records, error) {
sl := make(record.Records, 0, to-from)
troot, err := t.self.GetDAGNode(t.root)
log.Println(t.root)
if log.If(err) {
return nil, err
}
root, err := t.next(troot)
if log.If(err) {
return nil, err
}
for i := 0; root != nil && i < to; i++ {
kkk, _ := root.Key()
if spam != nil {
if _, exist := spam[kkk]; exist {
log.Println(kkk, "is regarded as spam")
i--
continue
}
}
if i >= from {
r, errr := t.toRecord(root)
if log.If(errr) {
return nil, errr
}
sl = append(sl, r)
}
root, err = t.next(root)
if log.If(err) {
return nil, err
}
}
return sl, nil
}
示例4: Add
//Add adds record r and return true is thread was changed.
func (t *Thread) Add(r *record.Record) (bool, error) {
if t.name != r.Thread {
err := errors.New("thread name unmatch")
log.Println(err)
return false, err
}
rn, err := t.self.GetDAGNode(r.Key)
if log.If(err) {
return false, err
}
n := &merkledag.Node{}
if err := n.AddNodeLink("contents", rn); log.If(err) {
return false, err
}
nsign := &merkledag.Node{Data: r.Sign}
if err := n.AddNodeLink("sign", nsign); log.If(err) {
return false, err
}
troot, err := t.self.GetDAGNode(t.root)
if log.If(err) {
return false, err
}
troot, err = t.search(troot, r.Stamp, t.updateLink(n, r.Stamp))
if log.If(err) {
return false, err
}
log.Println(t.root)
if troot != nil {
t.root, err = t.self.AddDAGNode(troot, false)
}
log.Println(t.root)
log.If(err)
return troot != nil, err
}
示例5: nameResolve
//nameResolve resole name hash using IPNS.
func (p *Peer) nameResolve() (key.Key, error) {
log.Println("resolving", p.ID.Pretty())
pt, err := p.myself.ipfsNode.Namesys.Resolve(p.myself.ctx, "/ipns/"+p.ID.Pretty())
if log.If(err) {
return "", err
}
log.Println("resolved", pt)
seg := pt.Segments()
return key.B58KeyDecode(seg[len(seg)-1]), nil
}
示例6: Merge
//Merge merges all records in list which has key and returns true if updated .
func (l *List) Merge(tkey key.Key) (bool, error) {
if l.key == tkey {
log.Println("same key,nothing to do")
return false, nil
}
root, err := l.self.GetDAGNode(l.key)
if log.If(err) {
return false, err
}
troot, err := l.self.GetDAGNode(tkey)
if log.If(err) {
return false, err
}
var t *Thread
updated := false
for _, link := range troot.Links {
var k key.Key
if th, errr := l.self.GetLinkedNode(root, link.Name); errr == nil {
k, err = th.Key()
if log.If(err) {
return false, err
}
}
t, err = New(l.self, link.Name, k)
if log.If(err) {
return false, err
}
kk := key.Key(link.Hash)
if k == kk {
continue
}
log.Println("adding to " + link.Name)
u, errr := t.Merge(kk)
if log.If(errr) {
return false, err
}
if !u {
continue
}
tn, errr := t.self.GetDAGNode(t.Key())
if log.If(errr) {
return false, errr
}
root, errr = root.UpdateNodeLink(link.Name, tn)
if log.If(errr) {
return false, errr
}
updated = true
}
if updated {
l.key, err = l.self.AddDAGNode(root, false)
log.If(err)
}
return updated, err
}
示例7: NewSelf
//NewSelf make repo if needed ,starts daemon and returns Self obj.
func NewSelf(cfg *config.Config, rootPath string) *Self {
InitRepo(cfg.IpfsRepo)
n := &merkledag.Node{}
k, err := n.Key()
log.IfFatal(err)
//workaround "ERROR bitswap: failed to find any peer in table"
i := 0
var node *core.IpfsNode
var ctx context.Context
var cancel context.CancelFunc
for i = 0; i < 10; i++ {
log.Println("setting up node...")
r, err := fsrepo.Open(cfg.IpfsRepo)
log.IfFatal(err)
ctx, cancel = context.WithCancel(context.Background())
node, err = core.NewNode(ctx, &core.BuildCfg{
Repo: r,
Online: true,
})
log.IfFatal(err)
if err := node.Routing.Provide(ctx, k); log.If(err) {
cancel()
log.If(node.Close())
log.Println("retrying...")
continue
}
break
}
if i == 10 {
log.Fatal("cannot provide a key to network")
}
self := &Self{
RootPath: rootPath,
ipfsNode: node,
ctx: ctx,
cancel: cancel,
cfg: cfg,
}
self.follow = FromStringSlice(cfg.FollowPeers, self)
parent, err := self.ToPeer().GetDAGNode("")
if log.If(err) {
parent = &merkledag.Node{}
}
self.myIpns, err = parent.Key()
log.IfFatal(err)
if _, err = parent.GetNodeLink(rootPath); err != nil {
log.Println("initializing DAGs for saving status")
self.makeInitNodes(parent)
}
return self
}
示例8: StartListen
//StartListen starts listening and calls accept fucn if accepted.
func (m *Self) StartListen(accept func(net.Stream) error) error {
list, err := corenet.Listen(m.ipfsNode, "/app/"+m.RootPath)
if log.If(err) {
return err
}
log.Printf("starting to listen at peer: %s\n", m.ipfsNode.Identity.Pretty())
go func() {
for {
con, err := list.Accept()
defer func() {
log.If(con.Close())
}()
if log.If(err) {
continue
}
peer := con.Conn().RemotePeer()
log.Printf("Connection from: %s\n", peer)
p, err := FromBytes([]byte(peer), m)
if log.If(err) {
continue
}
if !p.IsAllowed() {
log.Println(p, "denifed")
continue
}
log.If(accept(con))
}
}()
return nil
}
示例9: LoadInitPeers
//LoadInitPeers loads init peers from the setting.
func (m *Self) LoadInitPeers() Peers {
peers := make(Peers)
for _, p := range m.cfg.InitPeers.GetData() {
pe, errr := New(p, m)
log.Println("peer name", p)
log.IfFatal(errr)
peers.Add(pe)
}
log.Println("loaded init peers")
if len(peers) == 0 {
log.Println("Warning: no peers in init_peers.txt")
}
err := m.WritePeers(peers)
log.IfFatal(err)
return peers
}
示例10: New
//New reeturns Manager obj.
func New(cfg *config.Config, rootPath string) (*Manager, error) {
self := peer.NewSelf(cfg, rootPath)
m := &Manager{
self: self,
}
p := self.ToPeer()
recent, err := p.ReadRecent()
if log.If(err) {
log.Println(err)
}
m.recent, err = thread.NewList(self, recent)
m.peers, err = p.ReadPeers()
log.If(err)
if len(m.peers) == 0 {
m.peers = self.LoadInitPeers()
}
m.tags, err = p.ReadTags()
log.If(err)
m.spams, err = p.ReadSpams()
log.If(err)
m.readThreads = self.ReadThreads()
if err := self.StartListen(m.accept); log.If(err) {
return nil, err
}
go func() {
for {
m.cron()
time.Sleep(time.Hour)
}
}()
return m, nil
}
示例11: WritePeersToDAG
//WritePeersToDAG writes peer list and returns merkledag key.
func (m *Self) WritePeersToDAG(peers Peers, kprev key.Key) (key.Key, error) {
log.Println("writing peers prev:", kprev)
var nodes NodesProto
nodes.Id = make([][]byte, len(peers))
i := 0
for _, p := range peers {
nodes.Id[i] = []byte(p.ID)
i++
}
dat, err := proto.Marshal(&nodes)
if log.If(err) {
return "", err
}
n := &merkledag.Node{Data: dat}
if kprev != "" {
prev, errr := m.GetDAGNode(kprev)
if log.If(errr) {
return "", errr
}
if err = n.AddNodeLink("prev", prev); log.If(err) {
return "", err
}
}
k, err := m.AddDAGNode(n, true)
if log.If(err) {
return "", err
}
return k, nil
}
示例12: GetDAGNode
//GetDAGNode returns merkledag node.
func (m *Self) GetDAGNode(k key.Key) (*merkledag.Node, error) {
log.Println("get dag node key", k)
n, err := m.ipfsNode.DAG.Get(m.ctx, k)
if log.If(err) {
return nil, err
}
return n, nil
}
示例13: readDAG
func (p *Peer) readDAG(pt string, obj proto.Message) error {
log.Println("reading DAG from", pt)
pa := p.myself.RootPath + "/" + pt
n, err := p.GetDAGNode(pa)
if log.If(err) {
return err
}
return proto.Unmarshal(n.Data, obj)
}
示例14: check
//check checks the record. i.e. check that it has valid Stamp, Thread, and valid pubKey if Signed.
func (r *Record) check(mustSigned bool) error {
if r.Stamp.UnixNano() <= 0 || r.Stamp.After(time.Now()) {
err := errors.New("Stamp not found")
log.Println(err)
return err
}
if r.Thread == "" {
err := errors.New("Thread not found")
log.Println(err)
return err
}
if mustSigned && r.Sign == nil {
err := errors.New("not Signed")
log.Println(err)
return err
}
if r.Sign == nil {
return nil
}
pubKey := r.Contents["pubkey"]
if pubKey == nil {
err := errors.New("no pubKey")
log.Println(err)
return err
}
pk, err := crypto.UnmarshalPublicKey(pubKey)
if log.If(err) {
return err
}
ok, err := pk.Verify([]byte(r.Key), r.Sign)
if err == nil && !ok {
err = errors.New("Sign unmatched")
}
if log.If(err) {
return err
}
/* if !r.self.cfg.RegSpam.Check(r.Contents) {
err := errors.New("regarded as spam")
log.Println(err)
return err
}
*/
return nil
}
示例15: fromString
func fromString(datastr string) (*linkName, error) {
if !strings.HasPrefix(datastr, linkNamePrefix) {
err := errors.New("don't have fixed prefix")
log.Println(err)
return nil, err
}
data := []byte(datastr[len(linkNamePrefix):])
if len(data) != lenName {
err := errors.New("illegal length of data")
log.Println(err)
return nil, err
}
stamp := time.Unix(0, int64(binary.BigEndian.Uint64(data)))
log.Println(stamp)
l := &linkName{
stamp: stamp,
}
return l, nil
}