<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def atlasdb_add_peer( peer_hostport, discovery_time=None, peer_table=None, con=None, path=None, ping_on_evict=True ):
 """ Add a peer to the peer table. If the peer conflicts with another peer, ping it first, and only insert the new peer if the old peer is dead. Keep the in-RAM peer table cache-coherent as well. Return True if this peer was added to the table (or preserved) Return False if not """

    
    # bound the number of peers we add to PEER_MAX_DB
    assert len(peer_hostport) > 0

    sk = random.randint(0, 2**32)
    peer_host, peer_port = url_to_host_port( peer_hostport )

    assert len(peer_host) > 0 

    peer_slot = int( hashlib.sha256("%s%s" % (sk, peer_host)).hexdigest(), 16 ) % PEER_MAX_DB

    with AtlasDBOpen(con=con, path=path) as dbcon:

        if discovery_time is None:
            discovery_time = int(time.time())

        do_evict_and_ping = False

        with AtlasPeerTableLocked(peer_table) as ptbl:

            # if the peer is already present, then we're done
            if peer_hostport in ptbl.keys():
                log.debug("%s already in the peer table" % peer_hostport)
                return True
           
            # not in the table yet.  See if we can evict someone
            if ping_on_evict:
                do_evict_and_ping = True


        if do_evict_and_ping:
            # evict someone
            # don't hold the peer table lock across network I/O
            sql = "SELECT peer_hostport FROM peers WHERE peer_slot = ?;"
            args = (peer_slot,)

            cur = dbcon.cursor()
            res = atlasdb_query_execute( cur, sql, args )

            old_hostports = []
            for row in res:
                old_hostport = res['peer_hostport']
                old_hostports.append( old_hostport )

            for old_hostport in old_hostports:
                # is this other peer still alive?
                # is this other peer part of the same mainnet history?
                # res = atlas_peer_ping( old_hostport )
                res = atlas_peer_getinfo(old_hostport)
                if res:
                    log.debug("Peer %s is still alive; will not replace" % (old_hostport))
                    return False

        # insert new peer
        with AtlasPeerTableLocked(peer_table) as ptbl:

            log.debug("Add peer '%s' discovered at %s (slot %s)" % (peer_hostport, discovery_time, peer_slot))

            # peer is dead (or we don't care).  Can insert or update
            sql = "INSERT OR REPLACE INTO peers (peer_hostport, peer_slot, discovery_time) VALUES (?,?,?);"
            args = (peer_hostport, peer_slot, discovery_time)

            cur = dbcon.cursor()
            res = atlasdb_query_execute( cur, sql, args )
            dbcon.commit()

            # add to peer table as well
            atlas_init_peer_info( ptbl, peer_hostport, blacklisted=False, whitelisted=False )
        
    return True