github.com/klaytn/klaytn@v1.10.2/cmd/kbn/api.go (about)

     1  // Copyright 2019 The klaytn Authors
     2  // This file is part of the klaytn library.
     3  //
     4  // The klaytn library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The klaytn library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the klaytn library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package main
    18  
    19  import (
    20  	"github.com/klaytn/klaytn/networks/p2p/discover"
    21  )
    22  
    23  type PublicBootnodeAPI struct {
    24  	bn *BN
    25  }
    26  
    27  func NewPublicBootnodeAPI(b *BN) *PublicBootnodeAPI {
    28  	return &PublicBootnodeAPI{bn: b}
    29  }
    30  
    31  func (api *PublicBootnodeAPI) GetAuthorizedNodes() []*discover.Node {
    32  	return api.bn.GetAuthorizedNodes()
    33  }
    34  
    35  type PrivateBootnodeAPI struct {
    36  	bn *BN
    37  }
    38  
    39  func NewPrivateBootnodeAPI(b *BN) *PrivateBootnodeAPI {
    40  	return &PrivateBootnodeAPI{bn: b}
    41  }
    42  
    43  func (api *PrivateBootnodeAPI) Name() string {
    44  	return api.bn.Name()
    45  }
    46  
    47  func (api *PrivateBootnodeAPI) Resolve(target discover.NodeID, targetType discover.NodeType) *discover.Node {
    48  	return api.bn.Resolve(target, targetType)
    49  }
    50  
    51  func (api *PrivateBootnodeAPI) Lookup(target discover.NodeID, targetType discover.NodeType) []*discover.Node {
    52  	return api.bn.Lookup(target, targetType)
    53  }
    54  
    55  func (api *PrivateBootnodeAPI) ReadRandomNodes(nType discover.NodeType) []*discover.Node {
    56  	var buf []*discover.Node
    57  	api.bn.ReadRandomNodes(buf, nType)
    58  	return buf
    59  }
    60  
    61  func (api *PrivateBootnodeAPI) CreateUpdateNodeOnDB(nodekni string) error {
    62  	return api.bn.CreateUpdateNodeOnDB(nodekni)
    63  }
    64  
    65  func (api *PrivateBootnodeAPI) CreateUpdateNodeOnTable(nodekni string) error {
    66  	return api.bn.CreateUpdateNodeOnTable(nodekni)
    67  }
    68  
    69  func (api *PrivateBootnodeAPI) GetNodeFromDB(id discover.NodeID) (*discover.Node, error) {
    70  	return api.bn.GetNodeFromDB(id)
    71  }
    72  
    73  func (api *PrivateBootnodeAPI) GetTableEntries() []*discover.Node {
    74  	return api.bn.GetTableEntries()
    75  }
    76  
    77  func (api *PrivateBootnodeAPI) GetTableReplacements() []*discover.Node {
    78  	return api.bn.GetTableReplacements()
    79  }
    80  
    81  func (api *PrivateBootnodeAPI) DeleteNodeFromDB(nodekni string) error {
    82  	return api.bn.DeleteNodeFromDB(nodekni)
    83  }
    84  
    85  func (api *PrivateBootnodeAPI) DeleteNodeFromTable(nodekni string) error {
    86  	return api.bn.DeleteNodeFromTable(nodekni)
    87  }
    88  
    89  func (api *PrivateBootnodeAPI) PutAuthorizedNodes(rawurl string) error {
    90  	return api.bn.PutAuthorizedNodes(rawurl)
    91  }
    92  
    93  func (api *PrivateBootnodeAPI) DeleteAuthorizedNodes(rawurl string) error {
    94  	return api.bn.DeleteAuthorizedNodes(rawurl)
    95  }