黑名单处理

可单独使用。

// This structure is used to do book keeping for the peer list and keeps other DATA related to peer
// all peers are servers, means they have exposed a port for connections
// all peers are identified by their endpoint tcp address
// all clients are identified by ther peer id ( however ip-address is used to control amount )
// the following daemon commands interact with the list
// bans := print current ban list
// ban address  time  // ban this address for specific time, if time not provided , default ban for 10 minutes
// unban address
// enableban address  // by default all addresses are bannable
// disableban address  // this address will never be banned

var ban_map = map[string]uint64{} // keeps ban maps

ban 的是指定 IP,并且设置 ban 的时长。以 map 形式存放,然后保存到 ban_list.json 文件。

内部主要被 Controller 调用,外部主要被 derod 调用。

方法:

load_ban_list

// loads peers list from disk

save_ban_list

//save ban list to disk

ban_clean_up_goroutine

// clean up ban list every 20 seconds

ban_clean_up

// clean up by discarding entries which are  in the past

ParseAddress

// convert address to subnet form
// address is an IP address or ipnet in string form

IsAddressInBanList

// check whether an IP is in the map already
//  we should loop and search in subnets also
// TODO make it fast, however we are not expecting millions of bans, so this may be okay for time being

Ban_Address

// ban a peer for specific time
// manual bans are always placed
// address can be an address or a subnet

UnBan_Address

// unban a peer for specific time

BanList_Print

// prints all the connection info to screen

Ban_Count

results matching ""

    No results matching ""