class Zold::NoSpamEntrance

The no-spam entrance

Public Class Methods

new(entrance, period: 60 * 60, log: Log::NULL) click to toggle source
# File lib/zold/node/nospam_entrance.rb, line 37
def initialize(entrance, period: 60 * 60, log: Log::NULL)
  @entrance = entrance
  @log = log
  @period = period
  @zache = Zache.new
end

Public Instance Methods

push(id, body) click to toggle source

Returns a list of modifed wallets (as Zold::Id)

# File lib/zold/node/nospam_entrance.rb, line 54
    def push(id, body)
      before = @zache.get(id.to_s, lifetime: @period) { '' }
      after = hash(id, body)
      if before == after
        @log.debug("Spam of #{id} ignored; the wallet content of #{Size.new(body.length)} \
and '#{after[0..8]}' hash has already been seen #{Age.new(@zache.mtime(id.to_s))} ago")
        return []
      end
      @zache.put(id.to_s, after)
      @entrance.push(id, body)
    end
start() { |self| ... } click to toggle source
# File lib/zold/node/nospam_entrance.rb, line 44
def start
  raise 'Block must be given to start()' unless block_given?
  @entrance.start { yield(self) }
end
to_json() click to toggle source
# File lib/zold/node/nospam_entrance.rb, line 49
def to_json
  @entrance.to_json
end

Private Instance Methods

hash(id, body) click to toggle source
# File lib/zold/node/nospam_entrance.rb, line 68
def hash(id, body)
  OpenSSL::Digest::SHA256.new(id.to_s + ' ' + body).hexdigest
end