Class: Zold::NoSpamEntrance

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/node/nospam_entrance.rb

Overview

The no-spam entrance

Instance Method Summary collapse

Constructor Details

#initialize(entrance, period: 60 * 60, log: Log::NULL) ⇒ NoSpamEntrance

Returns a new instance of NoSpamEntrance.



37
38
39
40
41
42
# 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

Instance Method Details

#push(id, body) ⇒ Object

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



54
55
56
57
58
59
60
61
62
63
64
# 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

#startObject



44
45
46
47
# 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_jsonObject



49
50
51
# File 'lib/zold/node/nospam_entrance.rb', line 49

def to_json
  @entrance.to_json
end